Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch undefined preprocessor macro with gcc?

I've been working on a piece of code that had an overlooked derp in it:

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

#define MAX_N_LENGTH 

/*function prototypes*/

int main(){
...
}

It should be easy to spot with the context removed: #define MAX_N_LENGTH should have read #define MAX_N_LENGTH 9. I have no idea where that trailing constant went.

Since that macro was only used in one place in the form of char buf[ MAX_N_LENGTH + 1], it was extremely difficult to track down and debug the program.

Is there a way to catch errors like this one using the gcc compiler?

like image 962
user1717828 Avatar asked Mar 11 '23 05:03

user1717828


1 Answers

You can use char buf[1 + MAX_N_LENGTH], because char buf[1 +] should not compile with the error message error: expected expression before ']' token:

http://ideone.com/5m2LYw

like image 104
mch Avatar answered Mar 20 '23 23:03

mch