DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: #ifndef and #pragma once

  1. #1
    Exitus Guest

    #ifndef and #pragma once


    Greetings,

    What is the preferred way of preventing multiple inclusions of header files
    in C++? I've see two way of doing it: #ifndef and #pragma once. What are
    the differences between the two and what are the pros and cons of using one
    over the other? Is it more a matter of personal choice or is there something
    behind the scenes that makes one better than the other?

    Thanks,
    Exitus

  2. #2
    Danny Kalev Guest

    Re: #ifndef and #pragma once

    the #ifdef is the portable, IDE independent form. The pragma once is not
    exactly the same, it ensures that the header file is #included *and
    compiled* only once. the #ifdef solution ensures that the header isn't
    #included more than once. I prefer the #ifdef solution. I usually prefer
    standard solutions to compiler specific hack because it makes your life
    easier when porting code.

    Danny

    Exitus wrote:
    >
    > Greetings,
    >
    > What is the preferred way of preventing multiple inclusions of header files
    > in C++? I've see two way of doing it: #ifndef and #pragma once. What are
    > the differences between the two and what are the pros and cons of using one
    > over the other? Is it more a matter of personal choice or is there something
    > behind the scenes that makes one better than the other?
    >
    > Thanks,
    > Exitus


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center