user3202429
user3202429

Reputation: 117

Make same #define in every file

I want to make a script that add a file ID number at every .C and .H file. This is used to identity from which file a error message is generated.

So every file has a unique number like:

fileID        (magic)

The problem is this only needs to exits in that file. Because every file have it's own.

edit: I need a number and not a string. So __FILE__ doesn't work.

Upvotes: 3

Views: 165

Answers (1)

Mihir Luthra
Mihir Luthra

Reputation: 6769

I generally use this macro for my error messages:

#define P_ERR(format, ...) \
    fprintf(stderr, "%s:%d:%s: " format "\n", __FILE__, __LINE__, strerror(errno), ##__VA_ARGS__)

You can read about all such macros in the docs.

Specific for __FILE__:

__FILE__ This macro expands to the name of the current input file, in the form of a C string constant. This is the path by which the preprocessor opened the file, not the short name specified in ‘#include’ or as the input file name argument. For example, "/usr/local/include/myheader.h" is a possible expansion of this macro.

Upvotes: 6

Related Questions