preprocessing statements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Cunningham

    preprocessing statements

    I have been thinking about hiding headers from my compiler's
    preprocessor and allowing others to be shown. I want to use the most used
    and add others is necessary. Would this be how it is properly done. I want
    to ask ahead of time because what I do might work but it might not be the
    "correct" or standard way.

    #include <stdio.h>
    #include <stdlib.h>
    #ifdef LINUX
    #include <unistd.h>
    #include <sys/types>
    #include <sys/stats.h>
    #include <fctnl.h>
    #endif

    Is the #endif needed at the end of this case ?

    Bill


  • Walter Roberson

    #2
    Re: preprocessing statements

    In article <vXX_j.5092$nx6 .2636@trnddc03> ,
    Bill Cunningham <nospam@nspam.c omwrote:
    >#include <stdio.h>
    >#include <stdlib.h>
    >#ifdef LINUX
    >#include <unistd.h>
    >#include <sys/types>
    >#include <sys/stats.h>
    >#include <fctnl.h>
    >#endif
    Is the #endif needed at the end of this case ?
    Yes. Every #if or #ifdef must have a matching #endif
    --
    "We may gather out of history a policy, by the comparison and
    application of other men's forepassed miseries with our own like
    errors and ill deservings." -- Sir Walter Raleigh

    Comment

    • vippstar@gmail.com

      #3
      Re: preprocessing statements

      On May 27, 8:56 pm, "Bill Cunningham" <nos...@nspam.c omwrote:
      I have been thinking about hiding headers from my compiler's
      preprocessor and allowing others to be shown. I want to use the most used
      and add others is necessary. Would this be how it is properly done. I want
      to ask ahead of time because what I do might work but it might not be the
      "correct" or standard way.
      That doesn't make sense, please re-attempt to explain your intentions,
      without being so ambiguous/vague.
      #include <stdio.h>
      #include <stdlib.h>
      #ifdef LINUX
      #include <unistd.h>
      #include <sys/types>
      #include <sys/stats.h>
      #include <fctnl.h>
      Just what is wrong with you Bill?
      Haven't you understood yet such thing is not topical for comp.lang.c?
      #endif
      >
      Is the #endif needed at the end of this case ?
      What's so hard about removing it and trying to compile? Or reading
      about #ifdef in your book?
      Isn't it the obvious thing to do before asking a group of people about
      it?

      Comment

      • Bill Cunningham

        #4
        Re: preprocessing statements


        <vippstar@gmail .comwrote in message news:175c11eb-5ef5-4c4b-b9bd-
        Haven't you understood yet such thing is not topical for comp.lang.c?
        Why is precrossing directives OT ?

        Bill



        Comment

        • santosh

          #5
          Re: preprocessing statements

          Bill Cunningham wrote:
          >
          <vippstar@gmail .comwrote in message news:175c11eb-5ef5-4c4b-b9bd-
          >Haven't you understood yet such thing is not topical for comp.lang.c?
          >
          Why is precrossing directives OT ?
          <clc-mode>
          "Precrossin g directives" _are_ OT. They aren't mentioned anywhere in the
          current and previous C standards. :-)
          </clc-mode>

          Seriously though, no preprocessing directives are perfectly topical.
          vippstar was talking about the various system specific headers that you
          had included in your code. Those _are_ OT and I believe better
          addressed in comp.unix.progr ammer. But your actual question can be
          answered here and Walter Roberson did so. Also your method to
          conditionally compile the include directives is perfectly fine. That's
          how it's done.

          Comment

          • vippstar@gmail.com

            #6
            Re: preprocessing statements

            On May 27, 9:18 pm, santosh <santosh....@gm ail.comwrote:
            Bill Cunningham wrote:
            >
            <vipps...@gmail .comwrote in message news:175c11eb-5ef5-4c4b-b9bd-
            Haven't you understood yet such thing is not topical for comp.lang.c?
            >
            Why is precrossing directives OT ?
            >
            <clc-mode>
            "Precrossin g directives" _are_ OT. They aren't mentioned anywhere in the
            current and previous C standards. :-)
            </clc-mode>
            >
            Seriously though, no preprocessing directives are perfectly topical.
            vippstar was talking about the various system specific headers that you
            had included in your code. Those _are_ OT and I believe better
            addressed in comp.unix.progr ammer. But your actual question can be
            answered here and Walter Roberson did so. Also your method to
            conditionally compile the include directives is perfectly fine. That's
            how it's done.
            Notice that he snipped the part I was addressing to; He *knew* which
            part I was talking about, and he *knew* why I called it off-topic.
            I'm inclined to believe his typo was intentional as well.
            Of course, all these are just assumptions...

            Comment

            • Walter Roberson

              #7
              Re: preprocessing statements

              In article <175c11eb-5ef5-4c4b-b9bd-8732f61584fa@a1 g2000hsb.google groups.com>,
              <vippstar@gmail .comwrote:
              >On May 27, 8:56 pm, "Bill Cunningham" <nos...@nspam.c omwrote:
              >#ifdef LINUX
              >#include <unistd.h>
              >#include <sys/types>
              >#include <sys/stats.h>
              >#include <fctnl.h>
              >Just what is wrong with you Bill?
              >Haven't you understood yet such thing is not topical for comp.lang.c?
              >#endif
              Such things *are* topic to comp.lang.c -- provided that it is
              recognized that including any header not defined by the C standard
              will result in the inclusion of implementation-defined content,
              with implementation-defined results (especially if one of the
              C keywords or standard routine names got #define'd into something
              unexpected.)

              The question posed could be answered just fine under those assumptions.
              We don't have to know what is in those headers to answer the question
              that was posed: we only have to know what the generic meaning of #include is.

              It's not like Bill did something nasty like using #define to try to
              splice together a trigraph and use that as part of the target file
              name for #include
              --
              "Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson

              Comment

              • santosh

                #8
                Re: preprocessing statements

                vippstar@gmail. com wrote:
                On May 27, 9:18 pm, santosh <santosh....@gm ail.comwrote:
                >Bill Cunningham wrote:
                >>
                <vipps...@gmail .comwrote in message news:175c11eb-5ef5-4c4b-b9bd-
                >Haven't you understood yet such thing is not topical for
                >comp.lang.c?
                >>
                Why is precrossing directives OT ?
                >>
                ><clc-mode>
                >"Precrossin g directives" _are_ OT. They aren't mentioned anywhere in
                >the current and previous C standards. :-)
                ></clc-mode>
                >>
                >Seriously though, no preprocessing directives are perfectly topical.
                >vippstar was talking about the various system specific headers that
                >you had included in your code. Those _are_ OT and I believe better
                >addressed in comp.unix.progr ammer. But your actual question can be
                >answered here and Walter Roberson did so. Also your method to
                >conditionall y compile the include directives is perfectly fine.
                >That's how it's done.
                Notice that he snipped the part I was addressing to; He *knew* which
                part I was talking about, and he *knew* why I called it off-topic.
                I'm inclined to believe his typo was intentional as well.
                Of course, all these are just assumptions...
                He is by no means a conventional troll and at times he really does seem
                genuine enough. He has indicated that he suffers from the after-effects
                of some drugs he has been prescribed, and I suppose each respondent has
                to accept the explanation or optionally ignore him.

                Comment

                • Keith Thompson

                  #9
                  Re: preprocessing statements

                  roberson@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
                  [...]
                  It's not like Bill did something nasty like using #define to try to
                  splice together a trigraph and use that as part of the target file
                  name for #include
                  Which would be perfectly topical (but the answer would be either "No"
                  or "Aaaauuuggghhh! ").

                  --
                  Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                  Nokia
                  "We must do something. This is something. Therefore, we must do this."
                  -- Antony Jay and Jonathan Lynn, "Yes Minister"

                  Comment

                  • Bill Cunningham

                    #10
                    Re: preprocessing statements


                    "santosh" <santosh.k83@gm ail.comwrote in message
                    news:g1hl26$rje $1@registered.m otzarella.org.. .
                    > Why is precrossing directives OT ?
                    >>>
                    >><clc-mode>
                    >>"Precrossin g directives" _are_ OT. They aren't mentioned anywhere in
                    >>the current and previous C standards. :-)
                    >></clc-mode>
                    >>>
                    >>Seriously though, no preprocessing directives are perfectly topical.
                    >>vippstar was talking about the various system specific headers that
                    >>you had included in your code. Those _are_ OT and I believe better
                    >>addressed in comp.unix.progr ammer. But your actual question can be
                    >>answered here and Walter Roberson did so. Also your method to
                    >>conditional ly compile the include directives is perfectly fine.
                    >>That's how it's done.
                    >Notice that he snipped the part I was addressing to; He *knew* which
                    >part I was talking about, and he *knew* why I called it off-topic.
                    >I'm inclined to believe his typo was intentional as well.
                    >Of course, all these are just assumptions...
                    [snip]

                    My question was about preprocessor directives. Yes it was a typo. The
                    headers I posted if they were relevant to the question I understand would be
                    off topic. They were just an example of using the preprocessor to block out
                    headers not needed. The question concern #if and #ifdef which seems to be it
                    looks like now to mean the same thing. #endif also was inquired to.

                    Bill


                    Comment

                    • Bill Cunningham

                      #11
                      Re: preprocessing statements


                      <vippstar@gmail .comwrote in message
                      news:29acd2f7-63b1-4af9-bcf8-98223bc1c95a@d4 5g2000hsc.googl egroups.com...
                      Notice that he snipped the part I was addressing to; He *knew* which
                      part I was talking about, and he *knew* why I called it off-topic.
                      I'm inclined to believe his typo was intentional as well.
                      Of course, all these are just assumptions...
                      irrelevant parts of post deleted. Relevant parts concerning preprocessor
                      directives included.

                      Bill


                      Comment

                      • Bill Cunningham

                        #12
                        Re: preprocessing statements


                        "santosh" <santosh.k83@gm ail.comwrote in message
                        news:g1hl26$rje $1@registered.m otzarella.org.. .
                        >>Seriously though, no preprocessing directives are perfectly topical.
                        >>vippstar was talking about the various system specific headers that
                        >>you had included in your code. Those _are_ OT and I believe better
                        >>addressed in comp.unix.progr ammer. But your actual question can be
                        >>answered here and Walter Roberson did so. Also your method to
                        >>conditional ly compile the include directives is perfectly fine.
                        >>That's how it's done.
                        [snip]

                        So then is it ok to talk about and use examples of #if and #ifdef and so
                        on. Or is preprocessing directives OT ?

                        Bill


                        Comment

                        • Walter Roberson

                          #13
                          Re: preprocessing statements

                          In article <y3Z_j.3437$fk. 3100@trnddc06>,
                          Bill Cunningham <nospam@nspam.c omwrote:
                          My question was about preprocessor directives. Yes it was a typo. The
                          >headers I posted if they were relevant to the question I understand would be
                          >off topic. They were just an example of using the preprocessor to block out
                          >headers not needed. The question concern #if and #ifdef which seems to be it
                          >looks like now to mean the same thing. #endif also was inquired to.
                          In this thread you did not ask about #if vs #ifdef . They do not mean
                          the same thing. For example,

                          #define FOO 0
                          #ifdef FOO
                          /* this section *will* be compiled, because FOO -is- defined. */
                          #endif
                          #if FOO
                          /* this section will *not* be compiled, because FOO's value is 0,
                          and #if 0 is false */
                          #endif
                          #ifdef if
                          /* this section will *not* be compiled, because the macro if is -not-
                          defined. */
                          #endif
                          #if !if
                          /* this section *will* be compiled. In a #if line, after all known
                          macros are expanded, all remaining identifiers have the value 0
                          substituted, without any consideration as to whether the identifiers
                          might be C keywords or library functions. With no macro named if,
                          the line would be equivilent to #if !0 which is #if 1 which is true. */
                          #endif
                          --
                          "The whole history of civilization is strewn with creeds and
                          institutions which were invaluable at first, and deadly
                          afterwards." -- Walter Bagehot

                          Comment

                          • Walter Roberson

                            #14
                            Re: preprocessing statements

                            In article <A9Z_j.3439$fk. 489@trnddc06>,
                            Bill Cunningham <nospam@nspam.c omwrote:
                            So then is it ok to talk about and use examples of #if and #ifdef and so
                            >on. Or is preprocessing directives OT ?
                            preprocessing directives are on-topic . There is only a problem if
                            the specific content of any #include'd non-standard file is relevant
                            to the question -- though questions about which identifiers are
                            predefined for specific implementations would also be off-topic
                            (except for the small number of identifiers documented in the C standard.)
                            --
                            "Let me live in my house by the side of the road --
                            It's here the race of men go by.
                            They are good, they are bad, they are weak, they are strong
                            Wise, foolish -- so am I;" -- Sam Walter Foss

                            Comment

                            • Keith Thompson

                              #15
                              Re: preprocessing statements

                              "Bill Cunningham" <nospam@nspam.c omwrites:
                              [...]
                              My question was about preprocessor directives. Yes it was a typo. The
                              headers I posted if they were relevant to the question I understand would be
                              off topic. They were just an example of using the preprocessor to block out
                              headers not needed. The question concern #if and #ifdef which seems to be it
                              looks like now to mean the same thing. #endif also was inquired to.
                              No, #if and #ifdef are similar, but they don't mean the same thing.
                              Consult your text book to learn the difference.

                              --
                              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                              Nokia
                              "We must do something. This is something. Therefore, we must do this."
                              -- Antony Jay and Jonathan Lynn, "Yes Minister"

                              Comment

                              Working...