crocker@cbnewsc.ATT.COM (ronald.t.crocker) (01/12/90)
In article <2381@ektools.UUCP> randolph@ektools.UUCP (Gary L. Randolph) writes: >I want to use __LINE__ in an inline function as follows: ... code deleted > >Must I use a macro? That's one solution. __LINE__ is a cpp built-in. The way AT&T C++ (i.e. cfront and friends) work, cpp is run before cfront. Hence, after running cpp your program looks like class Trace { private: int state; public: Trace() { state = 1; } int assert() { return 9;} }; main() { Trace a; cout<<a.assert(); } Cpp, being your friend, replaced __LINE__ by the line number. I would just use __LINE__ as an argument to Trace::assert, or make a macro that uses __LINE__ as the argument to Trace::assert. > >Gary Ron Crocker AT&T Bell Laboratories, IHP 1A-213 (312) 713-5262 ...!att!iexist!crocker -- Ron Crocker AT&T Bell Laboratories, IHP 1A-213 (312) 713-5262 ...!att!iexist!crocker
jimad@microsoft.UUCP (JAMES ADCOCK) (01/12/90)
In article <2381@ektools.UUCP> randolph@ektools.UUCP (Gary L. Randolph) writes: >Please tell me I'm missing something obvious here! >I want to use __LINE__ in an inline function as follows: Your missing something obvious here. [Which I'm well aware of, having tried this once too.] Namely CPP macro expansion happens before any C++ stuff, so when C++ sucks up the inline function to be regurgitated later [suitably modified] __LINE__ is already 9. So, in fact, as claimed, inlines are not macros, and excepting bugs work just like normal function calls except generating bigger, faster, harder to debug code -- and also doing a real good job of exercising any remaining bugs/restrictions in your underlying C code generator. --I would claim this is just yet another indication that CPP is a hack, and needs to be replaced with features in the language/compilers to handle most normal everyday programming tasks, including debugging support, import/export, asserts, condition compilers, templates, etc. CPP is untyped, unsafe, frequently used in unsyntactic ways, etc. Try writing reasonable tools to munge C/C++ sources. You can't. To parse C/C++ code you have to have valid syntax, and strict knowledge of when a word is a type-identifier, and CPP defeats all this. IMHO. [Not to rekindle an old flame]