CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    166

    Is #pragma once ok to use as a guard mechanism?

    Hello,

    sometimes I see guard mechanisms in .h files like so:

    #ifndef _CLASSNAME_H_
    #define _CLASSNAME_H_

    ...

    #endif //(_CLASSNAME_H_)

    doesnt "#pragma once" do the exact same thing but in one line of code? Why would anyone use the first method instead of "#pragma once" ?

    Thank you,
    Ellay

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Is #pragma once ok to use as a guard mechanism?

    pragmas are not standard. -> if you want to be able to compile your code with different compilers it's better to use ordinary include guards.
    kurt

  3. #3
    Join Date
    Mar 2008
    Posts
    30

    Re: Is #pragma once ok to use as a guard mechanism?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured