Is there a portable way to print a message from the C preprocessor?

Andrew Wagner picture Andrew Wagner · Sep 30, 2010 · Viewed 78.7k times · Source

I would like to be able to do something like

#print "C Preprocessor got here!"

for debugging purposes. What's the best / most portable way to do this?

Answer

You picture You · Sep 30, 2010

The warning directive is probably the closest you'll get, but it's not entirely platform-independent:

#warning "C Preprocessor got here!"

AFAIK this works on most compilers except MSVC, on which you'll have to use a pragma directive:

#pragma message ( "C Preprocessor got here!" )