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. Other Discussions
  3. The Weird and The Wonderful
  4. Linux C PreProcessor: Who Knew?

Linux C PreProcessor: Who Knew?

Scheduled Pinned Locked Moved The Weird and The Wonderful
linuxc++htmltutorial
8 Posts 5 Posters 17 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.
  • R Offline
    R Offline
    raddevus
    wrote on last edited by
    #1

    I'm going through a book right now which is fantastic! It's the best intro to OSes (how they are designed/programmed) I believe you'll ever read. First of all, you can read it for FREE online (PDFs). Operating Systems: Three Easy Pieces[^] Have you read the book? It's fantastic because it starts out with simple code examples (in C) that teach one specific point at a time. Amazing! If you've never read it, please skip all the (intro nonsense) & go right for the meat (to get an idea of how great the book is). Read this chapter[^] (be aware this will open the PDF in your browser) & I believe you'll be convinced how great the book is too. And Now For the Weird & Wonderful While examining the common_threads.h file for the 3rd example I stumbled upon these lines:

    #ifdef __linux__
    #include #endif

    I always wonder about strange things like that and in this case I thought, "Where is the __linux__ defined?" I looked it up and discovered Gnu docs for the C PreCompiler (cpp exe)[^]. I tried the command they suggested:

    $ cpp -dM

    But when I did I could see that cpp was running but just had an empty string. You actually have to point it at an exe and it'll pull out all the preprocessor commands. What!?!

    $ cpp -dM ./threadx

    When I ran that I saw a huge list of PreProcess commands. Huge! I then ran it thru grep like this:

    $ cpp -dM ./iox | grep -i linux

    I saw the following!!

    #define __linux 1
    #define __gnu_linux__ 1
    #define linux 1
    #define __linux__ 1

    So, I can see that over the years the convention to determine which OS the compiler is running on has changed. :wtf: Wow, things get messy as time goes on, don't they. BONUS Here's my favorite pre-processor define I found in the list. :rolleyes:

    #define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966F128

    T D K 3 Replies Last reply
    0
    • R raddevus

      I'm going through a book right now which is fantastic! It's the best intro to OSes (how they are designed/programmed) I believe you'll ever read. First of all, you can read it for FREE online (PDFs). Operating Systems: Three Easy Pieces[^] Have you read the book? It's fantastic because it starts out with simple code examples (in C) that teach one specific point at a time. Amazing! If you've never read it, please skip all the (intro nonsense) & go right for the meat (to get an idea of how great the book is). Read this chapter[^] (be aware this will open the PDF in your browser) & I believe you'll be convinced how great the book is too. And Now For the Weird & Wonderful While examining the common_threads.h file for the 3rd example I stumbled upon these lines:

      #ifdef __linux__
      #include #endif

      I always wonder about strange things like that and in this case I thought, "Where is the __linux__ defined?" I looked it up and discovered Gnu docs for the C PreCompiler (cpp exe)[^]. I tried the command they suggested:

      $ cpp -dM

      But when I did I could see that cpp was running but just had an empty string. You actually have to point it at an exe and it'll pull out all the preprocessor commands. What!?!

      $ cpp -dM ./threadx

      When I ran that I saw a huge list of PreProcess commands. Huge! I then ran it thru grep like this:

      $ cpp -dM ./iox | grep -i linux

      I saw the following!!

      #define __linux 1
      #define __gnu_linux__ 1
      #define linux 1
      #define __linux__ 1

      So, I can see that over the years the convention to determine which OS the compiler is running on has changed. :wtf: Wow, things get messy as time goes on, don't they. BONUS Here's my favorite pre-processor define I found in the list. :rolleyes:

      #define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966F128

      T Offline
      T Offline
      trønderen
      wrote on last edited by
      #2

      raddevus wrote:

      First of all, you can read it for FREE online (PDFs). Operating Systems: Three Easy Pieces[^]

      When I open the link, it tells me that the PDF version is USD 10. I am not that curious about the book.

      Religious freedom is the freedom to say that two plus two make five.

      J R 2 Replies Last reply
      0
      • R raddevus

        I'm going through a book right now which is fantastic! It's the best intro to OSes (how they are designed/programmed) I believe you'll ever read. First of all, you can read it for FREE online (PDFs). Operating Systems: Three Easy Pieces[^] Have you read the book? It's fantastic because it starts out with simple code examples (in C) that teach one specific point at a time. Amazing! If you've never read it, please skip all the (intro nonsense) & go right for the meat (to get an idea of how great the book is). Read this chapter[^] (be aware this will open the PDF in your browser) & I believe you'll be convinced how great the book is too. And Now For the Weird & Wonderful While examining the common_threads.h file for the 3rd example I stumbled upon these lines:

        #ifdef __linux__
        #include #endif

        I always wonder about strange things like that and in this case I thought, "Where is the __linux__ defined?" I looked it up and discovered Gnu docs for the C PreCompiler (cpp exe)[^]. I tried the command they suggested:

        $ cpp -dM

        But when I did I could see that cpp was running but just had an empty string. You actually have to point it at an exe and it'll pull out all the preprocessor commands. What!?!

        $ cpp -dM ./threadx

        When I ran that I saw a huge list of PreProcess commands. Huge! I then ran it thru grep like this:

        $ cpp -dM ./iox | grep -i linux

        I saw the following!!

        #define __linux 1
        #define __gnu_linux__ 1
        #define linux 1
        #define __linux__ 1

        So, I can see that over the years the convention to determine which OS the compiler is running on has changed. :wtf: Wow, things get messy as time goes on, don't they. BONUS Here's my favorite pre-processor define I found in the list. :rolleyes:

        #define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966F128

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        I've got the dead tree version on my shelf. It is a very good book.

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

        R 1 Reply Last reply
        0
        • T trønderen

          raddevus wrote:

          First of all, you can read it for FREE online (PDFs). Operating Systems: Three Easy Pieces[^]

          When I open the link, it tells me that the PDF version is USD 10. I am not that curious about the book.

          Religious freedom is the freedom to say that two plus two make five.

          J Offline
          J Offline
          Jalapeno Bob
          wrote on last edited by
          #4

          It opened for me, no messages. What browser are you using??

          __________________ Lord, grant me the serenity to accept that there are some things I just can’t keep up with, the determination to keep up with the things I must keep up with, and the wisdom to find a good RSS feed from someone who keeps up with what I’d like to, but just don’t have the damn bandwidth to handle right now. © 2009, Rex Hammock

          1 Reply Last reply
          0
          • T trønderen

            raddevus wrote:

            First of all, you can read it for FREE online (PDFs). Operating Systems: Three Easy Pieces[^]

            When I open the link, it tells me that the PDF version is USD 10. I am not that curious about the book.

            Religious freedom is the freedom to say that two plus two make five.

            R Offline
            R Offline
            raddevus
            wrote on last edited by
            #5

            I re-tried both links (the one to the book's main web site) and the one directly to the PDF & both worked for me. Honestly the book is free so I hope you get a chance to take a look. Someone else has confirmed that they links worked too. Try the link to the main site and then try clicking the chapters in the grid. Maybe you'll be able to get it there.

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              I've got the dead tree version on my shelf. It is a very good book.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

              R Offline
              R Offline
              raddevus
              wrote on last edited by
              #6

              Dave Kreskowiak wrote:

              I've got the dead tree version on my shelf.

              Very cool that you've read it. I am really enjoying the code samples, because they : 1. touch on very basic but very clear topics 2. are self contained & don't require a lot to get them compiled. 3. Touch on important topics like file i/o, simple threading ideas, etc. Really amazing book so far.

              1 Reply Last reply
              0
              • R raddevus

                I'm going through a book right now which is fantastic! It's the best intro to OSes (how they are designed/programmed) I believe you'll ever read. First of all, you can read it for FREE online (PDFs). Operating Systems: Three Easy Pieces[^] Have you read the book? It's fantastic because it starts out with simple code examples (in C) that teach one specific point at a time. Amazing! If you've never read it, please skip all the (intro nonsense) & go right for the meat (to get an idea of how great the book is). Read this chapter[^] (be aware this will open the PDF in your browser) & I believe you'll be convinced how great the book is too. And Now For the Weird & Wonderful While examining the common_threads.h file for the 3rd example I stumbled upon these lines:

                #ifdef __linux__
                #include #endif

                I always wonder about strange things like that and in this case I thought, "Where is the __linux__ defined?" I looked it up and discovered Gnu docs for the C PreCompiler (cpp exe)[^]. I tried the command they suggested:

                $ cpp -dM

                But when I did I could see that cpp was running but just had an empty string. You actually have to point it at an exe and it'll pull out all the preprocessor commands. What!?!

                $ cpp -dM ./threadx

                When I ran that I saw a huge list of PreProcess commands. Huge! I then ran it thru grep like this:

                $ cpp -dM ./iox | grep -i linux

                I saw the following!!

                #define __linux 1
                #define __gnu_linux__ 1
                #define linux 1
                #define __linux__ 1

                So, I can see that over the years the convention to determine which OS the compiler is running on has changed. :wtf: Wow, things get messy as time goes on, don't they. BONUS Here's my favorite pre-processor define I found in the list. :rolleyes:

                #define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966F128

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

                You can get a list of the compiler Manifest Defines via

                echo | cc -dM -E -

                In my case, I get 442 #defines for c++, and 380 for cc. Interestingly, the C compiler and the pre-processor produce exactly the same manifest defines. Messing around with different C/C++ standards gets different values for different standard versions e.g -std=c89 or -std=gnu17 or -std=gnu++11, so might be worth inspecting, to see how you can tell whether you're compiling for C89, C99, or if you're using clang (#define __clang__), etc

                "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

                R 1 Reply Last reply
                0
                • K k5054

                  You can get a list of the compiler Manifest Defines via

                  echo | cc -dM -E -

                  In my case, I get 442 #defines for c++, and 380 for cc. Interestingly, the C compiler and the pre-processor produce exactly the same manifest defines. Messing around with different C/C++ standards gets different values for different standard versions e.g -std=c89 or -std=gnu17 or -std=gnu++11, so might be worth inspecting, to see how you can tell whether you're compiling for C89, C99, or if you're using clang (#define __clang__), etc

                  "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

                  R Offline
                  R Offline
                  raddevus
                  wrote on last edited by
                  #8

                  Very cool. Thanks for sharing :thumbsup:

                  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