Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is efficient to use #pragma once or #ifndef #endif?

Tags:

visual-c++

mfc

To avoid multiple includes of a header file, one of my friend suggested the following way

  #ifndef _INTERFACEMESSAGE_HPP
  #define _INTERFACEMESSAGE_HPP
  class CInterfaceMessage
  {
     / /Declaration of class goes here
  //i.e declaration of member variables and methods 
   private:
   int m_nCount;
     CString m_cStrMessage;
    public:
    CString foo(int);
 }
   #endif

where _INTERFACEMESSAGE_HPP is just an identifier

but when i declare a class using visual studio 2005 IDE I get a statement as #pragma once at the starting of the class definition when i took the help of msdn to find the purpose of #pragma once it gave me the following explanation

"Specifies that the file will be included (opened) only once by the compiler when compiling a source code file. "

Someone please tell which is the right approach?, if both are correct then what is the difference? is one approach is better than the other?

like image 914
karthik Avatar asked Apr 04 '11 10:04

karthik


People also ask

What does efficient use mean?

: capable of producing desired results especially without waste (as of time or energy)

What is a sentence for efficient?

"We are working to make the process more efficient." "Over time, she will become more efficient." Used with adverbs: "These machines are very efficient."

How do you use effective and efficient?

The words effective and efficient both mean "capable of producing a result," but there is an important difference. Effective means "producing a result that is wanted". Efficient means "capable of producing desired results without wasting materials, time, or energy".

What is efficient and example?

The definition of efficient is being productive with minimal effort. An example of efficient is a car that gets 60 miles to a gallon of gas. YourDictionary. Making good, thorough, or careful use of resources; not consuming extra. Especially, making good use of time or energy.


1 Answers

gcc has pragma once as deprecated. You should use the standard include guards. All pragma directives are by definition implementation defined. So, if you want portability, don't use them.

like image 191
karthik Avatar answered Sep 20 '22 15:09

karthik