Thread: what is a pragma comment?

  1. #1
    Shadow12345
    Guest

    what is a pragma comment?

    I have seen pragma comment used to include files to a program i.e
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "glu32.lib")

    however I don't see why they dont 'just use the #include directive. What is so special about #pragma comment?
    Is it just for library files and/or dlls?

    ok thanks in advanced

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I believe you use pragma when you include something not written in C (ie Pascal, Ada etc...) . Could be wrong, though...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537

    Re: what is a pragma comment?

    Originally posted by Shadow12345
    I have seen pragma comment used to include files to a program i.e
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "glu32.lib")

    however I don't see why they dont 'just use the #include directive. What is so special about #pragma comment?
    Is it just for library files and/or dlls?

    ok thanks in advanced
    Those lines above link the code to the opengl libraries. Without them it has to be done in the project settings (for VC++ anyway) whihc is just more hassle. Magos seems almost correct, but I am sure its not limited to stuff that isn't written in C - could be wrong though.

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >>however I don't see why they dont 'just use the #include directive.

    i dont think you can #include *.lib's
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  5. #5
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    "pragma" is simply used by compilers, kind of a same way as "include" .....the only difference is in between compilers and their own personal header files.......what i mean by this is that each compiler has precompiled header files that other compilers don't.........so by writing "pragma" instead of "include" you simply say that:

    "include this header file in, however if you don't have such file in your library then skip it......"

    hope this helps.....

    matheo917

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    God bless #pragma!!!

    NOW I KNOW HOW TO USE IT!!!!!

    Ciao

    Ohhh yeah, what the hell does #pragma once do???

    NOTE: I use MSVC++ 6

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    #pragma and include are two totally different things:

    #include copies text into the file before compilation.
    #pragma with *.lib files or dlls link your executable with this file.

    #pragma once should make sure that each file is only used once in compiling.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    #pragma once

    This will include the header file one time. It's a multiple inclusion guard much like #ifndef , #define, #endif

    However it is highly un-portable. I suggest you stick to the before mentioned method of inclusion guarding.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    What does pragma stand for? I doubt it is a real name, so it has to be a shortening of something (like stdio = standard input output).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Magos
    What does pragma stand for? I doubt it is a real name, so it has to be a shortening of something (like stdio = standard input output).

    Clicky

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. #pragma comment lib
    By George2 in forum Windows Programming
    Replies: 4
    Last Post: 04-14-2008, 07:28 AM
  2. Comment using // or /* &&& */
    By Roaring_Tiger in forum C Programming
    Replies: 3
    Last Post: 03-16-2005, 02:45 PM
  3. Programming a PIC 16F84 microcontroller in C
    By Iahim in forum C Programming
    Replies: 1
    Last Post: 05-13-2004, 02:23 PM
  4. what does #pragma do?
    By cbc in forum C++ Programming
    Replies: 2
    Last Post: 10-16-2003, 06:51 AM
  5. ObjModLib Compiler for pragma comment.
    By sean in forum C++ Programming
    Replies: 2
    Last Post: 12-26-2001, 02:55 PM