Reputation: 2072
Apperantly rumor has it that it is possible to #include a single line in C (possibly with gcc)
e.g.
#include <file.h> 5
To get like line 5. Cannot find anything like that in the cpp docs.
Or which preprocessors allow doing ugly hacks like that?!
Upvotes: 5
Views: 2265
Reputation: 500873
I've never heard of such a feature, and I have certainly not come across any preprocessors that would support it.
In any case, it sounds like a really bad idea. What if someone inserted a blank line at the top of file.h
... would you be happy for that change to break your program?
If you control file.h
, I think the best approach is to extract line 5 into a separate header, and #include
it both into file.h
and into your main program.
Upvotes: 5
Reputation: 1866
http://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html#Include-Syntax
not possible with gcc and if it is possible with some compiller's preprocessor it will create absolute mess.
Upvotes: 1
Reputation: 104708
you'd simply create a one line file if you want something portable -- i too don't know of a means to accomplish exactly what you are after otherwise.
Upvotes: 0
Reputation: 143269
Could it be that you confused it with
#line lineno filename
directive?
Upvotes: 2
Reputation: 181450
I don't think that's possible with GCC or any other compiler for that matter.
Upvotes: 2