Answer the question
In order to leave comments, you need to log in
C code that won't work in C++?
Extract from Wikipedia :
The C++ syntax is inherited from the C language. One of the design principles was to maintain compatibility with C. However, C++ is not strictly a superset of C; The set of programs that can be translated equally well by both C and C++ compilers is quite large, but does not include all possible C programs .
Answer the question
In order to leave comments, you need to log in
Variable Length Arrays (VLA).
#include "stdio.h"
int main() {
size_t n;
scanf("%Iu", n);
int array[n];
return 0;
}
restrict
, register variables, which are not present in C++.
Anyone will work. I will rename the file from .cpp to .c and whatever will work.
Here is an example with two files that compiles as both C and C++, but only links as C. The difference between languages is in the C tentative definition:
File ac:
int i;
int main()
{
i = 1;
return 0;
}
int i;
int f(void)
{
i = 1;
return 0;
}
$ gcc -std=c89 a.c b.c -o a
$ gcc -std=c99 a.c b.c -o a
$ gcc -std=c11 a.c b.c -o a
$ g++ a.c b.c -o a
/tmp/cc8AfU2T.o:(.bss+0x0): multiple definition of `i'
/tmp/ccBOJ29v.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question