Quantcast
Viewing latest article 10
Browse Latest Browse All 12

Answer by xhainingx for Should I stop using the term C/C++?

C was never a subset of C++. The most obvious example of this is int new;. This has been true since C89 and C++98, and the languages have only grown further from each other as new standards have come out.

Should I stop using the term C/C++

Yes

If the answer to #1 is yes, how would I call a program that use a mix of C and C++?

A source file is written in one language or the other. A program can consist of code from multiple languages working together, or an executable produced by linking different compiled objects. You would say the program was written in C and C++, "C/C++" is not a language.

Given that both of them are 'different' languages is it likely that at some point C++ compilers stop supporting code written in the C language

  1. They never did. char *a = malloc(10);. C and C++ have never been fully compatible for at least as long as they've had ISO standards (I don't know all the details about the pre-standardized days). click the links or see below for a file that is fine with C89 and up, but isn't valid under any C++ standard.

  2. afaik no, but I don't know much about the C working group.

/* A bunch of code that compiles and runs under C89 but fails under any C++ *//* type aliases and struct names occupy separate namespaces in C, not in C++ */struct S { int i; };typedef int S;struct Outer { struct Inner { int i; } in; };/* struct Inner will be Outer::Inner in C++ due to name scope */struct Inner inner;/* default return type of int in C, C++ functions need explicit return types */g() {    return 0;}/* C sees this as two declarations of the same integer, * C++ sees it as redefinition */int n;int n;/* K&R style argument type declarations */void h(i) int i; { }/* struct type declaration in return type */struct S2{int a;} j(void) { struct S2 s = {1}; return s; }/* struct type declaration in argument, stupid and useless, but valid *//*void dumb(struct S3{int a;} s) { } *//* enum/int assignment */enum E{A, B};enum E e = 1;void k() {    goto label; /* C allows jumping past an initialization */    {        int x = 0;label:        x = 1;    }}/* () in declaration means unspecified number of arguments in C, the definition * can take any number of arguments, * but means the same as (void) in C++  (definition below main) */void f();int main(void) {    f(1); /* doesn't match declaration in C++ */    {        /* new is a keyword in C++ */        int new = 0;    }    /* no stdio.h include results in implicit definiton in C.  However,     * as long as a matching function is found at link-time, it's fine.     * C++ requires a declaration for all called functions */    puts("C is not C++");    {        int *ip;        void *vp = 0;        ip = vp; /* cast required in C++, not in C */    }    return 0;}/* matches declaration in C, not in C++ */void f(int i) { }

I always feel it's worth mentioning that C is a subset of Objective-C.


Viewing latest article 10
Browse Latest Browse All 12

Trending Articles