portability and return

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eligiusz Narutowicz

    #16
    Re: portability and return

    "Bill Cunningham" <nospam@nspam.c omwrites:
    "Peter Nilsson" <airia@acay.com .auwrote in message
    news:3222fc05-7aee-4eb3-b874-eb55981751dd@v2 6g2000prm.googl egroups.com...
    >Bill Cunningham wrote:
    >>I have heard that return -1 is not portable.
    >>
    >Presumably you're talking about the return value from main()?
    >
    Yes. Would return -1 from a function other than main be ok? I'm guessing
    no but I thought I'd ask.
    >
    Bill
    You are for sure trolling. Please stop.

    Comment

    • Mark McIntyre

      #17
      Re: portability and return

      Eligiusz Narutowicz wrote:
      "Bill Cunningham" <nospam@nspam.c omwrites:
      >(stufff)
      You are for sure trolling. Please stop.
      No, in fact Bill has some learning difficulty as far as we can discern.
      --
      Mark McIntyre

      CLC FAQ <http://c-faq.com/>
      CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

      Comment

      • Eligiusz Narutowicz

        #18
        Re: portability and return

        Mark McIntyre <markmcintyre@s pamcop.netwrite s:
        Eligiusz Narutowicz wrote:
        >"Bill Cunningham" <nospam@nspam.c omwrites:
        >>(stufff)
        >
        >
        >You are for sure trolling. Please stop.
        >
        No, in fact Bill has some learning difficulty as far as we can
        discern.
        This is impossible. How can anyone at this stage ask if a normal "int"
        function can return -1 and then guess that it can not?

        Comment

        • Mark McIntyre

          #19
          Re: portability and return

          Eligiusz Narutowicz wrote:
          Mark McIntyre <markmcintyre@s pamcop.netwrite s:
          >
          >Eligiusz Narutowicz wrote:
          >>"Bill Cunningham" <nospam@nspam.c omwrites:
          >>>(stufff)
          >>
          >>You are for sure trolling. Please stop.
          >No, in fact Bill has some learning difficulty as far as we can
          >discern.
          >
          This is impossible. How can anyone at this stage ask if a normal "int"
          function can return -1 and then guess that it can not?
          Suggest you find out what "learning difficulties" means.

          Comment

          • Eligiusz Narutowicz

            #20
            Re: portability and return

            Mark McIntyre <markmcintyre@s pamcop.netwrite s:
            Eligiusz Narutowicz wrote:
            >Mark McIntyre <markmcintyre@s pamcop.netwrite s:
            >>
            >>Eligiusz Narutowicz wrote:
            >>>"Bill Cunningham" <nospam@nspam.c omwrites:
            >>>>(stufff)
            >>>
            >>>You are for sure trolling. Please stop.
            >>No, in fact Bill has some learning difficulty as far as we can
            >>discern.
            >>
            >This is impossible. How can anyone at this stage ask if a normal "int"
            >function can return -1 and then guess that it can not?
            >
            Suggest you find out what "learning difficulties" means.
            I know what learning difficulties means. Please do not be so rude. But I
            refuse to believe that someone who can get on usenet and post such
            questions does not know what a signed int is for returning from a
            function. It seems incredible. If he really is slow then he needs to be
            elsewhere than this group and perform a proper tutorial or course.

            Comment

            • Richard Tobin

              #21
              Re: portability and return

              In article <g0f0fq$69o$1@r egistered.motza rella.org>,
              Eligiusz Narutowicz <eligiuszdotnar u@hotmail.comwr ote:
              >This is impossible. How can anyone at this stage ask if a normal "int"
              >function can return -1 and then guess that it can not?
              If you look at the rest of the thread you will see that this is not
              what he meant: he just expressed himself badly. He really wanted to
              know if calling exit(-1) from functions other than main was just
              as unportable as returning -1 from main.

              -- Richard



              --
              :wq

              Comment

              • Mark McIntyre

                #22
                Re: portability and return

                Eligiusz Narutowicz wrote:
                Mark McIntyre <markmcintyre@s pamcop.netwrite s:
                >
                >Eligiusz Narutowicz wrote:
                >>Mark McIntyre <markmcintyre@s pamcop.netwrite s:
                >>>
                >>>No, in fact Bill has some learning difficulty as far as we can
                >>>discern.
                ....
                >>This is impossible.
                ....
                >Suggest you find out what "learning difficulties" means.
                >
                I know what learning difficulties means.
                Good. Then perhaps you could consider how on earth you can possibly know
                what is possible and impossible for someone you've never met?
                Please do not be so rude.
                *shrug*. It wasn't rude, but if you want to consider it so that's your
                prerogative.
                But I
                refuse to believe that someone who can get on usenet
                I can't help what you believe. I'm posting the facts as we know them and
                have observed from Bill's posts here over the last several years.

                Enough, no more - tis not so sweet now as it was before.

                Comment

                • Eligiusz Narutowicz

                  #23
                  Re: portability and return

                  Mark McIntyre <markmcintyre@s pamcop.netwrite s:
                  Eligiusz Narutowicz wrote:
                  >Mark McIntyre <markmcintyre@s pamcop.netwrite s:
                  >>
                  >>Eligiusz Narutowicz wrote:
                  >>>Mark McIntyre <markmcintyre@s pamcop.netwrite s:
                  >>>>
                  >>>>No, in fact Bill has some learning difficulty as far as we can
                  >>>>discern.
                  ...
                  >>>This is impossible.
                  ...
                  >>Suggest you find out what "learning difficulties" means.
                  >>
                  >I know what learning difficulties means.
                  >
                  Good. Then perhaps you could consider how on earth you can possibly
                  know what is possible and impossible for someone you've never met?
                  >
                  >Please do not be so rude.
                  >
                  *shrug*. It wasn't rude, but if you want to consider it so that's your
                  prerogative.
                  >
                  >But I
                  >refuse to believe that someone who can get on usenet
                  >
                  I can't help what you believe. I'm posting the facts as we know them
                  and have observed from Bill's posts here over the last several years.
                  >
                  Enough, no more - tis not so sweet now as it was before.
                  Sigh ok. But considering how you answer some not so slow people I am
                  astonished who think he is retarded as opposed to a troll. Someone who
                  is capable of posting to usnet surely understands brackets and scope in
                  C by now? I find it troubling that he can not. If he really is so slow
                  then maybe there are better places for him to learning C.

                  Comment

                  • soscpd@terra.com.br

                    #24
                    Re: portability and return



                    Last time I get into this thread, Bill say that he know enough about
                    the subject(by May 13, 6:47 pm). Something like "Thanks very much.
                    That answers my question completely".

                    Maybe one should create a new group called
                    comp.moderated. only.and.just.o nly.std.and.wiz .c

                    Regards
                    Rafael

                    Comment

                    • santosh

                      #25
                      Re: portability and return

                      Bill Cunningham wrote:
                      >
                      "Richard Tobin" <richard@cogsci .ed.ac.ukwrote in message
                      news:g0d3t6$26u i$1@pc-news.cogsci.ed. ac.uk...
                      >There's no problem returning -1 from main() either, as far as the C
                      >program is concerned. All that's undefined is how the "host
                      >environment" - the shell or operating system or parent program -
                      >interprets it. 0 (or EXIT_SUCCESS) indicates success. EXIT_FAILURE
                      >indicates failure. What anything else means depends on your system.
                      >
                      [snip]
                      >
                      That's what I am concerned with. How the host system will react.
                      What I
                      am really concerned with is what the standard says would run best on
                      any environment. I write small C programs in linux and I want to be
                      able to take the same source code to my windows system and compile it
                      there and get the same results. I am trying to get into the habit of
                      treating all code as development code so it would work in all host
                      environments.
                      In this case your best method (for now) is to use EXIT_SUCCESS and
                      EXIT_FAILURE as appropriate. This will work on all conforming
                      implementations . The only disadvantage is that there is only a single
                      abnormal termination status value. You probably won't need multiple
                      values for most programs, but if you do need them, then you may have to
                      place system specific code surrounded by #ifdefs.

                      Comment

                      • Bill Cunningham

                        #26
                        Re: portability and return


                        "Eligiusz Narutowicz" <eligiuszdotnar u@hotmail.comwr ote in message
                        news:g0f0fq$69o $1@registered.m otzarella.org.. .
                        This is impossible. How can anyone at this stage ask if a normal "int"
                        function can return -1 and then guess that it can not?
                        I don't believe that is what I asked. My post reads "portabilit y". Not
                        can an int type return an int. This is not so much about the return types of
                        C but portability of ending functions with success or failure on different
                        implementations . I have been told return -1 was "wrong" (not portable). I
                        wanted the voice of experience.

                        No tutorial has ever spoke to me about the reactions of different
                        implementations or this post would never have been made. I wanted to get
                        straight ending with success or failure with a function. I only post to clc
                        after I have
                        1) read a topic and am confused
                        2) and tried by trial and error and can't determine the straight answer by
                        trial and error.

                        I do have problems that are worsened by Klonopin. Read the side effects
                        of that. Confusion. But

                        I think you need to read the topic of a thread before guessing it's
                        about return types as per values other than the topic like success or
                        failure and its portability and the standard.


                        Comment

                        • Bill Cunningham

                          #27
                          Re: portability and return


                          [snip]

                          "Eligiusz Narutowicz" <eligiuszdotnar u@hotmail.comwr ote in message
                          news:g0f69i$8u4 $2@registered.m otzarella.org.. .
                          Sigh ok. But considering how you answer some not so slow people I am
                          astonished who think he is retarded as opposed to a troll. Someone who
                          is capable of posting to usnet surely understands brackets and scope in
                          C by now?
                          Brackets and scope? Yes I understand that. What does that have to do with
                          anything? It's "implmentations " and "portabilit y" that was the question. And
                          I never expected this thread to become this large. I thought 2-4 responses
                          would be made. I am grateful to those who have answered my question(s).

                          [snip]



                          Comment

                          • Bart

                            #28
                            Re: portability and return

                            On May 14, 10:03 pm, "Bill Cunningham" <nos...@nspam.c omwrote:
                            "Eligiusz Narutowicz" <eligiuszdotn.. .@hotmail.comwr ote in message
                            >
                            news:g0f0fq$69o $1@registered.m otzarella.org.. .
                            >
                            This is impossible. How can anyone at this stage ask if a normal "int"
                            function can return -1 and then guess that it can not?
                            >
                                No tutorial has ever spoke to me about the reactions of different
                            implementations or this post would never have been made. I wanted to get
                            straight ending with success or failure with a function. I only post to clc
                            after I have
                            1) read a topic and am confused
                            2) and tried by trial and error and can't determine the straight answer by
                            trial and error.
                            This my approach to return in main():

                            (1) Completely ignore it
                            (2) If you /have/ to return a value, return anything (really, mostly
                            it doesn't matter)
                            (3) If someone/something complains, or it /does/ matter, return one of
                            EXIT_SUCCESS or EXIT_FAILURE, but those stick out like a sore thumb,
                            ruining the lines of my code (I don't like capitals much)

                            Your tutorial is taking the attitude that it's of little practical
                            importance to someone learning the language, which sounds right. There
                            are many more interesting things to worry about!

                            --
                            Bartc

                            Comment

                            • Keith Thompson

                              #29
                              Re: portability and return

                              "Bill Cunningham" <nospam@nspam.c omwrites:
                              "Eligiusz Narutowicz" <eligiuszdotnar u@hotmail.comwr ote in message
                              news:g0f0fq$69o $1@registered.m otzarella.org.. .
                              >This is impossible. How can anyone at this stage ask if a normal "int"
                              >function can return -1 and then guess that it can not?
                              >
                              I don't believe that is what I asked. My post reads "portabilit y". Not
                              can an int type return an int. This is not so much about the return types of
                              C but portability of ending functions with success or failure on different
                              implementations . I have been told return -1 was "wrong" (not portable). I
                              wanted the voice of experience.
                              [...]

                              I think your question was already answered, but I'll summarize.

                              A program can return a status code (of type int) to the host
                              environment (as it terminates) either by calling exit() with the
                              desired status as an argument, or by executing a return statement
                              within main(), returning the desired status. These two are
                              essentially equivalent. exit() can be called from anywhere, not just
                              from main().

                              The only portable status codes are 0, EXIT_SUCCESS, and EXIT_FAILURE.
                              Other values can be useful, but only in code intended for a particular
                              system.

                              Results returned by functions other than main() generally have
                              *nothing* to do with program status codes, so the advice to use 0,
                              EXIT_SUCCESS, or EXIT_FAILURE does not apply. The value you should
                              return from main() (or, equivalently, the value you should pass to
                              exit() is constrained by the host environment. The value you should
                              return from any other function is constrained by the requirements for
                              that function, something internal to your program.

                              Please feel free to ignore the following paragraph.

                              Returning a value from main and calling exit() with that same value
                              are *almost* equivalent. They can differ in an obscure and unlikely
                              scenario involving the atexit() function. They can also differ if you
                              call main() recursively, something that there's practically never a
                              good reason to do.

                              --
                              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

                              • Keith Thompson

                                #30
                                Re: portability and return

                                Bart <bc@freeuk.comw rites:
                                [...]
                                This my approach to return in main():
                                >
                                (1) Completely ignore it
                                (2) If you /have/ to return a value, return anything (really, mostly
                                it doesn't matter)
                                (3) If someone/something complains, or it /does/ matter, return one of
                                EXIT_SUCCESS or EXIT_FAILURE, but those stick out like a sore thumb,
                                ruining the lines of my code (I don't like capitals much)
                                Here's a better approach.

                                (1) Add ``return 0;'' immediately before the closing brace of your
                                main() function. Just think of it as part of the syntax.
                                (2) If you need to indicate failure, use EXIT_FAILURE. That's what
                                it's for. If you don't like capital letters, get over it.
                                (3) Consider using other values only if you need system-specific
                                status information.

                                --
                                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...