Thread: inclusion guards

  1. #1

    inclusion guards

    When writing header files I've always used the folowing format

    #ifndef HEADER_H
    #define HEADER_H
    //code here
    Now I've bought a C++ .Net book and it uses an alternative approach:

    #pragma once

    Is this better or worse or does it not make any difference which one I use?


  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    #pragma once

    is NOT defined in C++ and therefore is not guaranteed to be portable from compiler to compiler. It's in the .NET book because they are most-likely assuming you are using MSVC++ .NET (a compiler which defines the command to only open the file it is in once).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Header file multiple inclusion question
    By Loctan in forum C++ Programming
    Replies: 16
    Last Post: 05-04-2008, 08:25 PM
  2. Source file inclusion
    By sh3rpa in forum C++ Programming
    Replies: 7
    Last Post: 10-02-2007, 11:10 AM
  3. MSVC #pragma once and inclusion guards
    By cboard_member in forum Tech Board
    Replies: 4
    Last Post: 12-23-2006, 08:17 AM
  4. Header inclusion causing errors
    By cjschw in forum C++ Programming
    Replies: 12
    Last Post: 08-11-2004, 03:48 PM
  5. Header file include guards
    By foniks munkee in forum C Programming
    Replies: 4
    Last Post: 03-22-2002, 12:33 AM