+ 1

What does a define statement with an identifier but without a value do in C?

Consider this statement: #define FOO What does this code do? I know that this can be used to set flags in C (using #ifdef) but what actually happens when I do something like this? Obviously, 'FOO' won't be replaced by anything.

19th May 2021, 11:31 AM
Calvin Thomas
Calvin Thomas - avatar
4 Respostas
+ 2
'FOO' will be replaced by nothing, like literally, nothing. https://code.sololearn.com/cSlLGZJTOxKP/?ref=app
19th May 2021, 12:23 PM
XXX
XXX - avatar
+ 3
Calvin Thomas 'FOO' must be an individual token. The preprocessor will not replace 'FOO' if it is part of another token, like in 'pFOOf'. If the preprocessor replaced all occurrences of 'FOO' even when it is a part of another token, you won't be able to have a string "FOO" as it will be changed to "rint".
19th May 2021, 3:47 PM
XXX
XXX - avatar
+ 3
XXX Thank you very much. That too was really helpful
19th May 2021, 4:21 PM
Calvin Thomas
Calvin Thomas - avatar
+ 2
XXX That was really helpful. Thanks a lot. And, why doesn't this work?:- #include <stdio.h> #define FOO rint int main() { pFOOf("Hello World"); }
19th May 2021, 2:33 PM
Calvin Thomas
Calvin Thomas - avatar