need

M

Michael Tsang

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
tell me one program that works on c but not on c++?

main(){ /* implicit int declaration */
int new=0; /* reserved word in C++ */
printf("%d\n",new); /* implicit function declaration */
return 0;
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkqnuE0ACgkQG6NzcAXitM9NMQCcCxKD3a3FUo9lcdjPXor1nnnO
OOIAn113NrCKcB4yK8YHlAhJD26pRKgv
=Ls3l
-----END PGP SIGNATURE-----
 
D

Default User

Michael said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


main(){ /* implicit int declaration */
int new=0; /* reserved word in C++ */
printf("%d\n",new); /* implicit function declaration */
return 0;
}

Implicit function declarations have been out of C since the release of
the 1999 standard. Even under c89, use of a variadic function without a
prototype in scope is undefined behavior.



Brian
 
P

Paul N

tell me one program that works on c but not on c++?

#include <stdlib.h>

int main(void) {
int *ptr = malloc(10);
return 0;
}


In C++ you need to cast the result from malloc, which is unnecessary
(and discouraged) in C.

Alternatively, as Michael Tsang pointed out, you could use an
identifier (such as "new") which is a keyword in C++.

Paul.
 
J

Joshua Maurice

Don't forget sizeof('x'). It's sizeof(int) or sizeof(char), depending
on if it's compiled as C or C++.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top