what is difference between sizeof and strlen

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kenny McCormack

    #46
    Re: what is difference between sizeof and strlen

    In article <lnoe884a2t.fsf @nuthaus.mib.or g>,
    Keith Thompson <kst-u@mib.org> wrote:
    ....[color=blue]
    >In response to comments made elsewhere in this thread, none of this
    >has anything whatsoever to do with "religion". We are simply giving
    >you the best advice we can. If this comes across as "You must do
    >things this way because you'll go to Hell if you don't!", please feel
    >free to ask for clarification. There's almost always a valid reason
    >for the advice we give, but we don't always necessarily make that
    >sufficiently clear.[/color]

    I'm going to say this briefly and hope that the more intelligent readers
    can fill in the blanks and not worry about the lack of all the lawyerly
    bells and whistles that are ordinarily necessary.

    The content of this ng is religious in the sense that it has to do with the
    contents of a document - and, by extension, the goings on of the minds of
    the individuals who wrote that document. Science, on the other hand, is
    concerned with physical phenomena - things that are, in theory at least,
    verifyable by physical experimentation . So, in terms of science, someone
    can say "I've tested it - I've convinced myself - void main() works just
    fine" (*). Then religion comes along and says "No, it doesn't work - you
    cannot trust your senses. The document [sacred text] says it does not
    work". This is the essence of religion.

    I think the point is not so much that any particular thing (such as that
    which is currently under discussion) is a matter of religion as that the
    entire scope and charter of this ng is much more in line with a religious
    framework than that of a scientific one.

    And that's a strange thing to find in an ng under the comp.* hierarchy.

    (*) Equivalently: "They do move".

    Comment

    • Gordon Burditt

      #47
      Re: what is difference between sizeof and strlen

      >The content of this ng is religious in the sense that it has to do with the[color=blue]
      >contents of a document - and, by extension, the goings on of the minds of
      >the individuals who wrote that document. Science, on the other hand, is
      >concerned with physical phenomena - things that are, in theory at least,
      >verifyable by physical experimentation . So, in terms of science, someone
      >can say "I've tested it - I've convinced myself - void main() works just
      >fine" (*). Then religion comes along and says "No, it doesn't work - you
      >cannot trust your senses. The document [sacred text] says it does not
      >work". This is the essence of religion.[/color]

      Problems with void main() are observable. When I use such a program
      in a Makefile, it usually blows off the make with an error, because
      it returns status that looks like an error to make.

      Gordon L. Burditt

      Comment

      • Alan Balmer

        #48
        Re: what is difference between sizeof and strlen

        On Mon, 08 Aug 2005 19:16:46 GMT, gazelle@yin.int eraccess.com (Kenny
        McCormack) wrote:
        [color=blue]
        >In article <lnoe884a2t.fsf @nuthaus.mib.or g>,
        >Keith Thompson <kst-u@mib.org> wrote:
        >...[color=green]
        >>In response to comments made elsewhere in this thread, none of this
        >>has anything whatsoever to do with "religion". We are simply giving
        >>you the best advice we can. If this comes across as "You must do
        >>things this way because you'll go to Hell if you don't!", please feel
        >>free to ask for clarification. There's almost always a valid reason
        >>for the advice we give, but we don't always necessarily make that
        >>sufficientl y clear.[/color]
        >
        >I'm going to say this briefly and hope that the more intelligent readers
        >can fill in the blanks and not worry about the lack of all the lawyerly
        >bells and whistles that are ordinarily necessary.
        >
        >The content of this ng is religious in the sense that it has to do with the
        >contents of a document - and, by extension, the goings on of the minds of
        >the individuals who wrote that document. Science, on the other hand, is
        >concerned with physical phenomena - things that are, in theory at least,
        >verifyable by physical experimentation . So, in terms of science, someone
        >can say "I've tested it - I've convinced myself - void main() works just
        >fine" (*).[/color]

        No scientist would accept this as proof that void main() works just
        fine in another environment, or even at another time. It says only
        that this particular use, in this particular program, on this
        particular implementation, with the particular inputs used, worked as
        many times as I tested it. Any extension of this religious belief must
        be based on faith.
        [color=blue]
        > Then religion comes along and says "No, it doesn't work - you
        >cannot trust your senses. The document [sacred text] says it does not
        >work". This is the essence of religion.[/color]

        But nobody here is saying that. What we are saying is that the
        standard does not define what it does. That's an observable fact, as
        scientific as it gets. Proof requires only that one read the standard.[color=blue]
        >
        >I think the point is not so much that any particular thing (such as that
        >which is currently under discussion) is a matter of religion as that the
        >entire scope and charter of this ng is much more in line with a religious
        >framework than that of a scientific one.
        >
        >And that's a strange thing to find in an ng under the comp.* hierarchy.
        >
        >(*) Equivalently: "They do move".[/color]
        --
        Al Balmer
        Balmer Consulting
        removebalmercon sultingthis@att .net

        Comment

        • Anton Petrusevich

          #49
          Re: what is difference between sizeof and strlen

          Keith Thompson wrote:
          [color=blue]
          > and since the latter is portable, there is no advantage in using the
          > former.[/color]

          Good point. This is just my experience that says me: "I have never seen a C
          compiler which generated different symbols for void main() and for int
          main()". And so in my mind it's not a big deal which defenition to use.
          [color=blue]
          > There's nothing religious about it. It's a matter of correctness
          > about which there are strong feelings, largely because certain people
          > and/or institutions have encouraged something that is incorrect for no
          > good reason.[/color]

          If you would call ANSI/ISO C standard as "Bible"... :)
          [color=blue]
          > Perhaps the word "religious" doesn't mean what you think
          > it means. (And if you want to discuss that further, please take it to
          > alt.usage.engli sh.)[/color]

          Is my English so bad?
          --
          Anton Petrusevich

          Comment

          • Mark McIntyre

            #50
            Re: what is difference between sizeof and strlen

            On Mon, 08 Aug 2005 22:12:28 +0200, in comp.lang.c , Anton Petrusevich
            <casus@att-ltd.biz> wrote:
            [color=blue]
            >This is just my experience that says me: "I have never seen a C
            >compiler which generated different symbols for void main() and for int
            >main()".[/color]

            I have, and so have many others in this group. On at least one machine
            I've used, void main() would cause the app to crash on exit, and/or
            generate random error messages on the console.
            [color=blue]
            >If you would call ANSI/ISO C standard as "Bible"... :)[/color]

            In this group, the ISO standard /is/ the Bible.
            [color=blue]
            >Is my English so bad?[/color]

            its okay, I've read much worse.
            --
            Mark McIntyre
            CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
            CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

            ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
            http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
            ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

            Comment

            • Richard Tobin

              #51
              Re: what is difference between sizeof and strlen

              In article <dd88lt$ctb$1@y in.interaccess. com>,
              Kenny McCormack <gazelle@intera ccess.com> wrote:[color=blue]
              >Probably not relevant to *you*[/color]

              I would have thought it was obvious that I meant relevant to the
              behaviour and correctness of C implementations , not to any one person.

              -- Richard

              Comment

              • Keith Thompson

                #52
                Re: what is difference between sizeof and strlen

                gazelle@yin.int eraccess.com (Kenny McCormack) writes:
                [...][color=blue]
                > The content of this ng is religious in the sense that it has to do with the
                > contents of a document - and, by extension, the goings on of the minds of
                > the individuals who wrote that document. Science, on the other hand, is
                > concerned with physical phenomena - things that are, in theory at least,
                > verifyable by physical experimentation . So, in terms of science, someone
                > can say "I've tested it - I've convinced myself - void main() works just
                > fine" (*). Then religion comes along and says "No, it doesn't work - you
                > cannot trust your senses. The document [sacred text] says it does not
                > work". This is the essence of religion.
                >
                > I think the point is not so much that any particular thing (such as that
                > which is currently under discussion) is a matter of religion as that the
                > entire scope and charter of this ng is much more in line with a religious
                > framework than that of a scientific one.
                >
                > And that's a strange thing to find in an ng under the comp.* hierarchy.
                >
                > (*) Equivalently: "They do move".[/color]

                No.

                What we do in this newsgroup isn't "science" in the sense of
                formulating hypotheses and theories and testing them by performing
                experiments in the real world and observing the results.

                It's more like mathematics, in which we start from a set of postulates
                and rules of inference and reason from them to reach conclusions.

                As far as "void main" is concerned, the standard does *not* say that
                it doesn't "work". To see what it does say, read any number of
                articles in this thread -- or read the standard itself.

                Arguing about whether void main() "works" in comp.lang.c is not unlike
                arguing about whether parallel lines can meet in Euclidean geometry.
                It is a fact that parallel lines cannot meet in Euclidean geometry,
                because that's one of the postulates on which it's built. It's also a
                fact that "parallel" lines can meet in some non-Euclidean geometries
                -- but then you're not talking about Euclidean geometry anymore.

                It is, of course, possible to discuss the relationship between
                Euclidean geometry and the real world (is space curved?), but strictly
                speaking that's not a discussion about Euclidean geometry. Similarly,
                it's possible to discuss the relationship between C and the real world
                (does gcc conform to this section of the standard?), but again,
                strictly speaking that's not a discussion of C, which is what this
                newsgroup is about.

                C is intended to be useful, of course, which is why the standard (the
                set of postulates from which we work) is designed to be both
                implementable (by compiler writers) and usable (by programmers).

                (If I were to concede that C is a religion, we'd merely being doing
                the equivalent of asking people to discuss their blasphemies *outside*
                the church doors so they don't interrupt the service. But I make no
                such concession.)

                --
                Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                We must do something. This is something. Therefore, we must do this.

                Comment

                • Keith Thompson

                  #53
                  Re: what is difference between sizeof and strlen

                  Anton Petrusevich <casus@att-ltd.biz> writes:[color=blue]
                  > Keith Thompson wrote:[color=green]
                  >> and since the latter is portable, there is no advantage in using the
                  >> former.[/color]
                  >
                  > Good point. This is just my experience that says me: "I have never seen a C
                  > compiler which generated different symbols for void main() and for int
                  > main()". And so in my mind it's not a big deal which defenition to use.[/color]

                  The advantage of staying within the limits defined by the standard
                  whenever possible is that you don't have to depend on your own
                  experience. If "void main()" has always worked for you in the past,
                  it could break tomorrow, and if you complain to your compiler vendor,
                  all he has to do is point to the standard. If you use "int main()"
                  and your program breaks, either something else is responsible for it
                  or you've found a compiler bug that the vendor had better fix if he
                  wants any repeat business.
                  [color=blue][color=green]
                  >> There's nothing religious about it. It's a matter of correctness
                  >> about which there are strong feelings, largely because certain people
                  >> and/or institutions have encouraged something that is incorrect for no
                  >> good reason.[/color]
                  >
                  > If you would call ANSI/ISO C standard as "Bible"... :)[/color]

                  Only jokingly.

                  The standard is a contract between implementers and programmers. It's
                  binding only on those who choose to accept it (or who are required to
                  do so by, say, their employers). There's no legal penalty for writing
                  a non-conforming compiler or a non-conforming program, but there are
                  real benefits to conformance. In this newsgroup, we usually take that
                  as given rather than continually re-explaining *why* it's good to have
                  a standard.
                  [color=blue][color=green]
                  >> Perhaps the word "religious" doesn't mean what you think
                  >> it means. (And if you want to discuss that further, please take it to
                  >> alt.usage.engli sh.)[/color]
                  >
                  > Is my English so bad?[/color]

                  Not at all, and if I had stopped to realize that you're probably not a
                  native speaker of English, I would have phrased that differently. (It
                  was also a reference to a line from the movie "The Princess Bride".)

                  --
                  Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                  San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                  We must do something. This is something. Therefore, we must do this.

                  Comment

                  • Chris Croughton

                    #54
                    Re: what is difference between sizeof and strlen

                    On Mon, 08 Aug 2005 22:12:28 +0200, Anton Petrusevich
                    <casus@att-ltd.biz> wrote:
                    [color=blue]
                    > Keith Thompson wrote:
                    >[color=green]
                    >> and since the latter is portable, there is no advantage in using the
                    >> former.[/color]
                    >
                    > Good point. This is just my experience that says me: "I have never seen a C
                    > compiler which generated different symbols for void main() and for int
                    > main()". And so in my mind it's not a big deal which defenition to use.[/color]

                    It's not necessarily different symbols, it could be different code
                    generated. For instance, it might insist on return values being passed
                    back on the stack, so that for a function returning int it would do a
                    POP to get the return value but not for a void function -- if your void
                    main doesn't put that value on the stack the calling routine will try to
                    pop something which isn't there, possibly causing a system crash.
                    [color=blue][color=green]
                    >> There's nothing religious about it. It's a matter of correctness
                    >> about which there are strong feelings, largely because certain people
                    >> and/or institutions have encouraged something that is incorrect for no
                    >> good reason.[/color]
                    >
                    > If you would call ANSI/ISO C standard as "Bible"... :)[/color]

                    I don't. I regard it the same way as a Health and Safety handbook -- if
                    you do things the way it says then you will be safe. If you don't,
                    you are on your own and better be very certain why you are doing it in a
                    different way. Not just "it saves typing a line".
                    [color=blue][color=green]
                    >> Perhaps the word "religious" doesn't mean what you think
                    >> it means. (And if you want to discuss that further, please take it to
                    >> alt.usage.engli sh.)[/color]
                    >
                    > Is my English so bad?[/color]

                    Not at all, it's better than most of the people who post to Usenet who
                    claim to be native English speakers (most of the errors you make look
                    like typos rather than lack of knowledge of English, and I make enough
                    of those that I can't criticise that!). However, native speakers of
                    English don't always understand the words they use properly either or
                    they use them in ways they weren't supposed to mean (especially
                    politicians and journalists -- you seem too sensible to be either of
                    those <g>) and "religious" is one of those over-used and wrongly used
                    words. So is "Bible", the word does literally mean just "book" but with
                    capital letter at start it refers to a specific book and shouldn't be
                    used casually to mean "any book I respect and follow" (indeed, the
                    Christian Bible would be madness to follow as literally as we do the C
                    standard!).

                    Chris C

                    Comment

                    • Richard Bos

                      #55
                      Re: what is difference between sizeof and strlen

                      gazelle@yin.int eraccess.com (Kenny McCormack) wrote:
                      [color=blue]
                      > I'm going to say this briefly and hope that the more intelligent readers
                      > can fill in the blanks and not worry about the lack of all the lawyerly
                      > bells and whistles that are ordinarily necessary.[/color]

                      I could put that even more briefly, but in the interest of civility I
                      won't.
                      [color=blue]
                      > The content of this ng is religious in the sense that it has to do with the
                      > contents of a document[/color]

                      The law is religious? Literature? Seems to me that you should go see a
                      real church from the inside, to know what you're talking about.

                      Richard

                      Comment

                      • Chris Dollin

                        #56
                        Re: what is difference between sizeof and strlen

                        Kenny McCormack wrote:
                        [color=blue]
                        > The content of this ng is religious in the sense that it has to do with
                        > the contents of a document - and, by extension, the goings on of the minds
                        > of
                        > the individuals who wrote that document. Science, on the other hand, is
                        > concerned with physical phenomena - things that are, in theory at least,
                        > verifyable by physical experimentation . So, in terms of science, someone
                        > can say "I've tested it - I've convinced myself - void main() works just
                        > fine" (*). Then religion comes along and says "No, it doesn't work - you
                        > cannot trust your senses. The document [sacred text] says it does not
                        > work". This is the essence of religion.[/color]

                        The document says that there is no obligation on the part of an implementor
                        to make `void main` "work" (whatever that means), so don't do it if you
                        want predictable results. This is not religion: it's contract law. Or
                        engineering.

                        Suppose, for example, that your local by-laws prevent you from running
                        a business from your home. You are free to experiment with running such
                        a business. You may even make a profit. However, should TPTB discover your
                        activities, you may experience undefined behaviour.

                        Suppose that you're building some circuit, and a 10-ohm resistance is
                        required [1]. You use a 7-ohm resistor, since your daughter used the last
                        10-ohm resistor yesterday as an earring, and you know from experience
                        that this "works". When this particular 7-ohm beast turns out to be at
                        the low end of the range and the smoke gets out and the circuit fails
                        in an embarassing (perhaps dangerous) fashion ...
                        [color=blue]
                        > I think the point is not so much that any particular thing (such as that
                        > which is currently under discussion) is a matter of religion as that the
                        > entire scope and charter of this ng is much more in line with a religious
                        > framework than that of a scientific one.[/color]

                        Computer science isn't a science; we already knew this.

                        Now, if you want /religious/ arguments, indentation, tab-size, global
                        variables, ncspellingOfVar iableNames, i++ vs ++i vs i += 1, for(;;) vs
                        while(1), &co, all seem to be waiting, fuel-soaked and steaming gently,
                        in the wings.

                        [1] All figures made up.

                        --
                        Chris "electric hedgehog" Dollin
                        Stross won one! Farah won one! Langford won TWO!

                        Comment

                        • Emmanuel Delahaye

                          #57
                          Re: what is difference between sizeof and strlen

                          Anton Petrusevich wrote on 08/08/05 :[color=blue][color=green][color=darkred]
                          >>> void main()[/color]
                          >> ^^^^
                          >> Why do so many people post without
                          >> c) learning the first thing about C from even the most basic textbook?[/color]
                          >
                          > What if I do not care about the return value of the program?[/color]

                          Who is 'I' ? AFAIK, 'I' is the system. You have no control on it.
                          Returning an undefined value to the system invokes an undefined
                          behaviour. Period.

                          --
                          Emmanuel
                          The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
                          The C-library: http://www.dinkumware.com/refxc.html

                          "C is a sharp tool"


                          Comment

                          • Anton Petrusevich

                            #58
                            Re: what is difference between sizeof and strlen

                            Emmanuel Delahaye wrote:
                            [color=blue][color=green]
                            >> What if I do not care about the return value of the program?[/color]
                            > Who is 'I' ? AFAIK, 'I' is the system. You have no control on it.
                            > Returning an undefined value to the system invokes an undefined
                            > behaviour. Period.[/color]

                            It (the behaviour) can be perfectly defined for some particular system. The
                            system just returns (undefined) & 255 to the process which executed the
                            program. And then this process reads that (undefined) octet and happily
                            throws it away. I am not interested in this discussion anymore.
                            --
                            Anton Petrusevich

                            Comment

                            • Chris Dollin

                              #59
                              Re: what is difference between sizeof and strlen

                              Anton Petrusevich wrote:
                              [color=blue]
                              > Martin Ambuhl wrote:
                              >[color=green][color=darkred]
                              >>> void main()[/color]
                              >> ^^^^
                              >> Why do so many people post without
                              >> c) learning the first thing about C from even the most basic textbook?[/color]
                              >
                              > What if I do not care about the return value of the program? Or better,
                              > what if I _do_ care but use exit(0)?[/color]

                              The Standard doesn't say what a `void main` might mean, so using it
                              isn't portable. It doesn't matter whether or not you call `exit`,
                              as far as I can tell.

                              --
                              Chris "electric hedgehog" Dollin
                              Stross won one! Farah won one! Langford won TWO!

                              Comment

                              • Emmanuel Delahaye

                                #60
                                Re: what is difference between sizeof and strlen

                                Anton Petrusevich wrote on 08/08/05 :[color=blue][color=green]
                                >> "Undefined behaviour" is a technical term in the C standard. It's not
                                >> really relevant whether *you* would call it that.[/color]
                                >
                                > I don't get it. I thought, and I still continue to think, that "undefined
                                > behaviour" means just that: when the behaviour is undefined. If the
                                > behaviour is dependent on some defined thing (platform) then it's
                                > "defined". You (or I) just need to know the platform. Of course, there's no
                                > such (defined) thing as "platform" in C standard, so they say "undefined
                                > behaviour". "int main()" is a tough religion, isn't it?[/color]

                                No matter what you think. Just stick to the facts. The C standard
                                defines a number of behaviours. Some others are clearly under the
                                responsability of the implementation (implementation-dependent). The
                                rest is simply 'undefined'. It's a fact. Period. There is nothing
                                really to argue about it.

                                What is undefined can do anything. The result is not predictable and
                                not reproducable. It's a bug. Period.

                                --
                                Emmanuel
                                The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
                                The C-library: http://www.dinkumware.com/refxc.html

                                I once asked an expert COBOL programmer, how to
                                declare local variables in COBOL, the reply was:
                                "what is a local variable?"


                                Comment

                                Working...