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. Preprocessor Directives in C Program

Preprocessor Directives in C Program

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 6 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.
  • A Offline
    A Offline
    Aakashdata
    wrote on last edited by
    #1

    What is the role of preprocessor directives in c program? What if, we don't use it?

    R L L 3 Replies Last reply
    0
    • A Aakashdata

      What is the role of preprocessor directives in c program? What if, we don't use it?

      R Offline
      R Offline
      Renuka peshwani
      wrote on last edited by
      #2

      Preprocessor are executed before compilation. This is a macro processor, which is used automatically by the C compiler to transform your program before actual compilation.

      In simple words, preprocessor directives tells the compiler to preprocess the source code before compiling. All the preprocessor commands are begin with "#" symbol.

      The most common use of the preprocessor is to include header files. In C and C++, all symbols must be declared in a file before they can used. They don’t always need to be defined*, but the compiler needs to know they exist somewhere. A preprocessor is just another technique to help a programming language be more useful. There are numerous techniques available and every language designer must choose the ones they like.

      1 Reply Last reply
      0
      • A Aakashdata

        What is the role of preprocessor directives in c program? What if, we don't use it?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Aakashdata wrote:

        What if, we don't use it?

        Depending on which one(s) you don't use, your program may not compile.

        1 Reply Last reply
        0
        • A Aakashdata

          What is the role of preprocessor directives in c program? What if, we don't use it?

          L Offline
          L Offline
          leon de boer
          wrote on last edited by
          #4

          You don't have to use Preprocessor Directives it is entirely up to you they are there to make life easy and are not mandatory at all. Here is a hello world without a single Preprocessor Directive :-)

          #include
          int main (void)
          {
          printf("hello world\n");
          return 0;
          }

          No Preprocessor Directive was harmed in the making of that code.

          In vino veritas

          K L 2 Replies Last reply
          0
          • L leon de boer

            You don't have to use Preprocessor Directives it is entirely up to you they are there to make life easy and are not mandatory at all. Here is a hello world without a single Preprocessor Directive :-)

            #include
            int main (void)
            {
            printf("hello world\n");
            return 0;
            }

            No Preprocessor Directive was harmed in the making of that code.

            In vino veritas

            K Offline
            K Offline
            k5054
            wrote on last edited by
            #5

            Umm ... I think you could argue that #include is, indeed a preprocessor directive. It does, after all tell the pre-processor to include the given file as part of the source text passed to the compiler.

            L 1 Reply Last reply
            0
            • K k5054

              Umm ... I think you could argue that #include is, indeed a preprocessor directive. It does, after all tell the pre-processor to include the given file as part of the source text passed to the compiler.

              L Offline
              L Offline
              leon de boer
              wrote on last edited by
              #6

              haha true ... lets try that again

              int main (void)
              {
              volatile int i = 0;
              i = i++;
              }

              Even stopped it optimizing away :-)

              In vino veritas

              P 1 Reply Last reply
              0
              • L leon de boer

                haha true ... lets try that again

                int main (void)
                {
                volatile int i = 0;
                i = i++;
                }

                Even stopped it optimizing away :-)

                In vino veritas

                P Offline
                P Offline
                Peter_in_2780
                wrote on last edited by
                #7

                leon de boer wrote:

                Even stopped it optimizing away

                but atill doesn't return the int it declares it will. ;P

                Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                L 1 Reply Last reply
                0
                • P Peter_in_2780

                  leon de boer wrote:

                  Even stopped it optimizing away

                  but atill doesn't return the int it declares it will. ;P

                  Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                  L Offline
                  L Offline
                  leon de boer
                  wrote on last edited by
                  #8

                  Hey it was late only a cup of coffee between good code and bad code !!! You are right I say return 0 to you :-)

                  In vino veritas

                  1 Reply Last reply
                  0
                  • L leon de boer

                    You don't have to use Preprocessor Directives it is entirely up to you they are there to make life easy and are not mandatory at all. Here is a hello world without a single Preprocessor Directive :-)

                    #include
                    int main (void)
                    {
                    printf("hello world\n");
                    return 0;
                    }

                    No Preprocessor Directive was harmed in the making of that code.

                    In vino veritas

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    As k5054 says, the #include is a preprocessor directive. But, even worse, it contains a plethora of other directives.

                    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