Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. #pragma once

#pragma once

Scheduled Pinned Locked Moved C / C++ / MFC
htmlcomquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hint_54
    wrote on last edited by
    #1

    I'm confused. If you have a header named "myheader.h" defined has:

    /*-----------------
    myheader.h
    -----------------*/
    #ifndef MyHeaderH
    #define MyHeaderH
    //-------------------------------
    // Everything else goes here
    //-------------------------------
    #endif // MyHeader

    Then what's the use of the "#pragma once" directive if both are used to include a file only once? Or am I wrong and they have different purposes? I've seen the "#pragma once" definition here Thanks in advance hint_54

    N D 2 Replies Last reply
    0
    • H hint_54

      I'm confused. If you have a header named "myheader.h" defined has:

      /*-----------------
      myheader.h
      -----------------*/
      #ifndef MyHeaderH
      #define MyHeaderH
      //-------------------------------
      // Everything else goes here
      //-------------------------------
      #endif // MyHeader

      Then what's the use of the "#pragma once" directive if both are used to include a file only once? Or am I wrong and they have different purposes? I've seen the "#pragma once" definition here Thanks in advance hint_54

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      Well AFAIK both accomplishes the same purpose. Apart from that(AFAIK) #pragma maintains a list of included files too.


      Nibu thomas Software Developer

      H 1 Reply Last reply
      0
      • N Nibu babu thomas

        Well AFAIK both accomplishes the same purpose. Apart from that(AFAIK) #pragma maintains a list of included files too.


        Nibu thomas Software Developer

        H Offline
        H Offline
        hint_54
        wrote on last edited by
        #3

        Then if I use only one of them its the same thing, right? regards PS: what does AFAIK mean?? hint_54

        N 1 Reply Last reply
        0
        • H hint_54

          I'm confused. If you have a header named "myheader.h" defined has:

          /*-----------------
          myheader.h
          -----------------*/
          #ifndef MyHeaderH
          #define MyHeaderH
          //-------------------------------
          // Everything else goes here
          //-------------------------------
          #endif // MyHeader

          Then what's the use of the "#pragma once" directive if both are used to include a file only once? Or am I wrong and they have different purposes? I've seen the "#pragma once" definition here Thanks in advance hint_54

          D Offline
          D Offline
          Dan McCormick
          wrote on last edited by
          #4

          from cplusplus.com[^] The pragma directive is used to specify diverse options to the compiler. These options are specific for the platform and the compiler you use. Consult the manual or the reference of your compiler for more information on the possible parameters that you can define with #pragma. If the compiler does not support a specific argument for #pragma, it is ignored - no error is generated. #pragma once is supported by many but not all compilers. If you want to write code that works with a number of compilers, you should use the old fasioned #define... method. Regards, Dan Remember kids, we're trained professionals.
          Don't try this at home!

          1 Reply Last reply
          0
          • H hint_54

            Then if I use only one of them its the same thing, right? regards PS: what does AFAIK mean?? hint_54

            N Offline
            N Offline
            Nibu babu thomas
            wrote on last edited by
            #5

            hint_54 wrote:

            Then if I use only one of them its the same thing, right?

            Dan has answered your query. :)

            hint_54 wrote:

            PS: what does AFAIK mean??

            As Far As I Know.:-D


            Nibu thomas Software Developer

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups