(FAQ details:) malloc(), void * and casts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Old Wolf

    #31
    Re: (FAQ details:) malloc(), void * and casts

    On Nov 20, 11:05 am, Julienne Walker <happyfro...@ho tmail.comwrote:
    On Nov 19, 2:41 pm, Paul Hsieh <websn...@gmail .comwrote:
    What are you talking about? I write code like that, pretty much
    exclusively nowadays. Its not challenging in the least. Certainly
    consumers of the Better String Library appreciate it.
    >
    I won't comment on your Better String Library, but a C library
    designed to work with C++ does fall under the exception I was talking
    about.
    He doesn't write a C library to work with C++. (FWIW, almost every
    C library works with C++, with minor header tweaks). He writes code
    that can either be compiled as a C library, or as a C++ library.
    Nobody can really explain why he does this.

    Comment

    • Joachim Schmitz

      #32
      Re: (FAQ details:) malloc(), void * and casts

      "santosh" <santosh.k83@gm ail.comschrieb im Newsbeitrag
      news:fhugev$iq5 $1@registered.m otzarella.org.. .
      While I can understand the problem of maintaining old code, I'd be very
      surprised of any current systems which have only a pre-ANSI C compiler
      available. Can you give an example?
      Not 100% sure, but I believe with HP/UX you get a pre ANSI Compiler as long
      as you don't buy/license a 'real' one (that ancient compiler seems to be
      needed/sufficient to create a new kernel)

      Bye, Jojo


      Comment

      • santosh

        #33
        Re: (FAQ details:) malloc(), void * and casts

        In article <fhuno9$i11$1@o nline.de>, Joachim Schmitz
        <nospam.jojo@sc hmitz-digital.dewrote on Tuesday 20 Nov 2007 7:03 pm:
        "santosh" <santosh.k83@gm ail.comschrieb im Newsbeitrag
        news:fhugev$iq5 $1@registered.m otzarella.org.. .
        >While I can understand the problem of maintaining old code, I'd be
        >very surprised of any current systems which have only a pre-ANSI C
        >compiler available. Can you give an example?
        >
        Not 100% sure, but I believe with HP/UX you get a pre ANSI Compiler as
        long as you don't buy/license a 'real' one (that ancient compiler
        seems to be needed/sufficient to create a new kernel)
        Understood, but I was asking for an example of a platform where a
        pre-ANSI compiler is the _only_ option.

        Certain embedded systems might have non-conformant compilers, but that's
        (I think) different from a pre-ANSI compiler.

        Comment

        • Richard Bos

          #34
          Re: (FAQ details:) malloc(), void * and casts

          CJ <nospam@nospam. comwrote:
          On 19 Nov 2007 at 19:51, Ian Collins wrote:
          CJ wrote:
          In many older implementations of the standard library, malloc is defined
          to return a char * rather than a void *, so including the cast makes
          your program more portable.
          >
          That's a very rare corner case. Such libraries probably require
          malloc.h as well.
          >
          I'm not sure I'd call it "very rare" - there's plenty of old iron out
          there.
          >
          Writing in the common subset of K&R C, C89 and C99 where possible costs
          you very little, and buys you additional portability.
          I'm sorry: writing

          func()
          short a;
          float b;
          {
          ...
          }

          instead of

          int func(short a, float b)
          {
          ...
          }

          costs very little? You might want to rethink that.

          In the case under discussion, casting malloc() calls causes your brain
          to rot. To be precise, it causes deterioration, frequently irreversible,
          of the parts that let you think "Hey! A cast! Better be careful, there's
          something iffy going on here."

          Richard

          Comment

          • Flash Gordon

            #35
            Re: (FAQ details:) malloc(), void * and casts

            santosh wrote, On 20/11/07 14:26:
            In article <fhuno9$i11$1@o nline.de>, Joachim Schmitz
            <nospam.jojo@sc hmitz-digital.dewrote on Tuesday 20 Nov 2007 7:03 pm:
            >
            >"santosh" <santosh.k83@gm ail.comschrieb im Newsbeitrag
            >news:fhugev$iq 5$1@registered. motzarella.org. ..
            >>While I can understand the problem of maintaining old code, I'd be
            >>very surprised of any current systems which have only a pre-ANSI C
            >>compiler available. Can you give an example?
            >Not 100% sure, but I believe with HP/UX you get a pre ANSI Compiler as
            >long as you don't buy/license a 'real' one (that ancient compiler
            >seems to be needed/sufficient to create a new kernel)
            >
            Understood, but I was asking for an example of a platform where a
            pre-ANSI compiler is the _only_ option.
            You can also get gcc for HP/UX, so you do not even have to pay to have a
            C89/C90/C95 compiler.

            I believe there are still a few people using a few ancient machines (or
            emulations of them) where the machine itself pre-dates the ANSI standard
            by far enough that no one has written an compiler for the target that
            supports the standard. I seem to remember someone on comp.std.c
            mentioning that they were in this position. I can't remember why they
            were using such ancient systems.
            Certain embedded systems might have non-conformant compilers, but that's
            (I think) different from a pre-ANSI compiler.
            It is very different.
            --
            Flash Gordon

            Comment

            • Lorenzo Villari

              #36
              Re: (FAQ details:) malloc(), void * and casts


              "Paul Hsieh" <websnarf@gmail .comha scritto nel messaggio
              news:2e48e6ca-bbef-4542-bd5f-0b329e72d74f@i2 9g2000prf.googl egroups.com...
              On Nov 19, 7:38 am, "Lorenzo Villari" <vll...@tiscali .itwrote:
              "Paul Hsieh" <websn...@gmail .comha scritto nel
              Urg. I shouldn't have put myself out there, now I can't dig up a
              concrete example. I am an avid user of the WATCOM C/C++ compilers.
              They decided to supply their C and C++ solutions as two separate
              compilers and at various times they have clearly put more effort into
              their C++ optimizer. I had some benchmarks somewhere long ago that
              demonstrated this.
              >
              2) What do you mean by "mantained" . Maybe that we have fewer C
              > compilers
              than C++ ones? If this is what you meant, I won't be too happy
              > about that
              >
              Well C compilers certainly still exist, and some vendors, like
              Microsoft, continue to use a single compiler that compiles both
              languages. But GNU, and Watcom have clearly taken the two compiler
              approach (but in different ways; GNU uses a common back end, at least
              for now.)
              There's a section in your site in which you do compare the assembler
              generated by the watcom compiler, in contrast with one done by hand by you.
              Over the first assembler listing I can read:

              "WATCOM C/C++ v10.0a output"

              so one has the impression they give identical output... but why have you
              used the C one anyway ? :)



              Comment

              Working...