Papers/programming

inline, macro

tomato13 2009. 9. 8. 10:04

http://stackoverflow.com/questions/216510/extern-inline


inline void printLocation()

{

  cout <<"You're at " __FILE__ ", line number" __LINE__;

}


{

...

  printLocation();

...

  printLocation();

...

  printLocation();


-------------------------------------------------

and hoping that you'll get different values printed each time. As Don says, you won't, because __FILE__ and __LINE__ are implemented by the preprocessor, but inline is implemented by the compiler. So wherever you call printLocation from, you'll get the same result.


The only way you can get this to work is to make printLocation a macro. (Yes, I know...)

--------------------------------------------------


#define PRINT_LOCATION  {cout <<"You're at " __FILE__ ", line number" __LINE__}


...

  PRINT_LOCATION;

...

  PRINT_LOCATION;

...

'Papers > programming' 카테고리의 다른 글

pthread example  (0) 2009.11.19
Difference Between Static & Global Variable  (0) 2009.09.12
vsprintf, vsnprintf  (0) 2009.08.28
extern "C"  (0) 2009.08.20
hpp file  (0) 2009.04.10