Here is an obscure c feature: int main() { int a = 8; { int a = 4; /* a is only scoped to this block */ } printf("%d", a); /* prints 8 */ } It is also why C++ is not a strict superset of C
Off the top of my head, I can't think of any language that doesn't permit this. See https://en.wikipedia.org/wiki/Variable_shadowing
Some Obscure C Features
21–30 of 147 posts
Re: Some Obscure C Features
#22Here is an obscure c feature: int main() { int a = 8; { int a = 4; /* a is only scoped to this block */ } printf("%d", a); /* prints 8 */ } It is also why C++ is not a strict superset of C
Re: Some Obscure C Features
#23Here is an obscure c feature: int main() { int a = 8; { int a = 4; /* a is only scoped to this block */ } printf("%d", a); /* prints 8 */ } It is also why C++ is not a strict superset of C
If you want to tell if your compiler is C or C++, run this program: #include int main() { printf("%d\n", sizeof('a')); } It's the second thing C++ mentions in its list of incompatibility with C (the first is "new keywords"). A more obscure difference is this program: int i; int i; int main() { return i; } It's legal C but not legal C++.
int main() {
return 4//**/2
;
}Re: Some Obscure C Features
#24Re: Some Obscure C Features
#25Here is an obscure c feature: int main() { int a = 8; { int a = 4; /* a is only scoped to this block */ } printf("%d", a); /* prints 8 */ } It is also why C++ is not a strict superset of C
Re: Some Obscure C Features
#26Wow. This has to be the best C obscurity that I've ever seen.
Re: Some Obscure C Features
#27Earlier quoted context omitted.
If you want to tell if your compiler is C or C++, run this program: #include int main() { printf("%d\n", sizeof('a')); } It's the second thing C++ mentions in its list of incompatibility with C (the first is "new keywords"). A more obscure difference is this program: int i; int i; int main() { return i; } It's legal C but not legal C++.
int main() { return 4//**/2 ; }
Re: Some Obscure C Features
#28Here is an obscure c feature: int main() { int a = 8; { int a = 4; /* a is only scoped to this block */ } printf("%d", a); /* prints 8 */ } It is also why C++ is not a strict superset of C
If you want to tell if your compiler is C or C++, run this program: #include int main() { printf("%d\n", sizeof('a')); } It's the second thing C++ mentions in its list of incompatibility with C (the first is "new keywords"). A more obscure difference is this program: int i; int i; int main() { return i; } It's legal C but not legal C++.
So if sizeof ('a') == 1, then either you're compiling as C++ or you're compiling as C under a rather odd implementation.
Both POSIX and Windows require CHAR_BIT==8. The only systems I know of with CHAR_BIT>8 are for digital signal processors (DSPs).
If you want to tell whether you're compiling C or C++:
#ifdef __cplusplus
...
#else
...
#fiRe: Some Obscure C Features
#29Although calling the preprocessor "functional" is being too pleasant. The C preprocessor was always a text substitution system, so macro as parameter is not that "obscure". Of course, I may have missed something subtle in the example. It's also not clear how to use that preprocessor example.
old but gold