I want to redefine the value of a macro constant with another value. Now I know the technique of using #undef and thereafter re-#define the macro itself, like:
#define LEN_OSG 59
....
#undef LEN_OSG
#define LEN_OSG 70
I´d attempt to abbreviate this and discovered that it is possible to redefine the macro constant by just another #define directive:
#define LEN_OSG 59
....
#define LEN_OSG 70
#include <stdio.h>
#define LEN_OSG 59
int main()
{
printf("LEN_OSG is %d.\n",LEN_OSG);
#define LEN_OSG 70
printf("LEN_OSG is %d.",LEN_OSG);
}
Of course, Both gcc and clang give me the warnings:
warning: "LEN_OSG" redefined. (gcc)
and
warning: 'LEN_OSG' macro redefined [-Wmacro-redefined] (clang)
but they do compile it (without the -Werror option of course) and give both the correct result:
Execution build compiler returned: 0
Program returned: 0
LEN_OSG is 59.
LEN_OSG is 70.
My questions:
- Can I redefine a macro with another #define directive by ignoring this specific warning?
- Does this in any kind involve undefined behavior or cause a potential harm to the program?
Thank you very much.