|
From: Ioannis V. <iv...@em...> - 2003-06-16 11:09:22
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Vlada Djurovic > Sent: Monday, June 16, 2003 11:52 AM > To: 'DevC++ help' > Subject: [Dev-C++] #pragma directive > > > In the book I'm currently reading, #pragma once directive is > used a lot to > make sure that no header files are included more than once. > When I compile > the program, I get warnings " #pragma once is obsolete". The book is > published this year, so I don't think it's too old. > I found another way for doing the same thing in Bruce Eckel's > "Thinking in > C++", like this: #pragmas are compiler dependend commands which are not portable. The standard says that when a #pragma directive is not recognised by the compiler it is ignored. So #pragma once is a directive recognised by MS compilers to include the header file only once. On the other hand the inclusion guard mechanism you are using below is portable and is what you should use (if you want your code to be portable). > > #ifndef FLAG > #define FLAG > #includefoo.h ///include needed headers > ------------- > #endif > > Which way is better in your opinion? Or do you recommend > something else? > Thanks. > ------------ > Vlada Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |