Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overwrite register keyword

Tags:

c++

c

Having in mind that register is a keyword and that we could use to name functions/methods (i really miss it), we can't do that. But I wonder, is it dangerous to overwrite that keyword?

#define register ...

Will be any kind of side effects?

like image 988
yayuj Avatar asked May 01 '26 13:05

yayuj


1 Answers

C++ says, in 17.6.4.3.1[macro.names]/2

A translation unit shall not #define or #undef names lexically identical to keywords

although this falls under

This section describes restrictions on C++ programs that use the facilities of the C++ standard library

C says, in 7.1.2/4

The program shall not have any macros with names lexically identical to keywords currently defined prior to the inclusion of the header or when any macro defined in the header is expanded

so, in C, you could put that after all #includes (Edit: as pointed out in comments, even in C, using a macro that comes from a standard library header after your #define would be formally undefined, since it might be using that keyword)

like image 69
Cubbi Avatar answered May 03 '26 03:05

Cubbi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!