Suppose I would like to write a preprocessor macro which would have a conditional branch inside built on whether an argument to that macro is l-value or r-value. Is that achievable with C (not C++, not C11), possibly with GCC extensions?
Asked
Active
Viewed 141 times
4
-
@StoryTeller I am asking about C, not C++. – Wojciech Migda Dec 04 '16 at 20:52
-
Gotcha, should have read more carefully – StoryTeller - Unslander Monica Dec 04 '16 at 20:53
-
I don't think this is possible – M.M Dec 04 '16 at 21:02
-
Do you wanna check it in compile time? – Felipe Lavratti Dec 05 '16 at 00:03
-
1Why do you say "C, ... not C11"? C11 *is* C. – Keith Thompson Dec 05 '16 at 02:41
-
@FelipeLavratti I am not sure it would be possible otherwise. – Wojciech Migda Dec 05 '16 at 08:34
-
@KeithThompson by that I mean C without C11 extensions. – Wojciech Migda Dec 05 '16 at 08:35
-
1C11 is not "extensions", it is the current version of the language. If you mean "C99 only", say so. – Keith Thompson Dec 05 '16 at 16:16
-
What do you want it for? – Petr Skocik Nov 20 '18 at 20:01
-
It's fundamentally impossible with just the preprocessor. gcc/clang probably do not have an extension for it. – Petr Skocik Nov 20 '18 at 20:03
-
@PSkocik I was curious if I could place such guard to conditionally assign a value in code like this: https://github.com/WojciechMigda/CSL/blob/master/src/move_ptr.h#L40 – Wojciech Migda Dec 12 '18 at 08:54
-
@WojciechMigda I don't believe such a check is available in modern compilers, but maybe, if your macro intends to modify, it should take a pointer instead of a value, hoping it's an lvalue. – Petr Skocik Dec 12 '18 at 11:10