Re: Source code for free() lib function

Discussion in 'C Programming' started by Joona I Palaste, Jul 2, 2003.

  1. asm_fool <> scribbled the following:
    > Where can I get the source code for the free() function according to
    > the latest standard?
    > Any URL reference please.


    There isn't "the source". The standard only specifies what the function
    should do, not how it should be implemented. This makes sense, as it
    does not tie C into one particular processor platform, but instead makes
    it a standard that can be adopted to just about every platform.
    If you really need the source code for free() on your particular
    implementation, ask in a newsgroup dedicated to that implementation.

    --
    /-- Joona Palaste () ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/
    "To know me IS to love me."
    - JIPsoft
     
    Joona I Palaste, Jul 2, 2003
    #1
    1. Advertising

  2. Joona I Palaste wrote:
    > asm_fool <> scribbled the following:
    >
    >>Where can I get the source code for the free() function according to
    >>the latest standard?
    >>Any URL reference please.

    >
    >
    > There isn't "the source". The standard only specifies what the function
    > should do, not how it should be implemented. This makes sense, as it
    > does not tie C into one particular processor platform, but instead makes
    > it a standard that can be adopted to just about every platform.
    > If you really need the source code for free() on your particular
    > implementation, ask in a newsgroup dedicated to that implementation.
    >

    Correct me if I am wrong, but wouldn't the following implementation
    fully comply to the standard and be portable pretty much anywhere <g> ?

    void free(void *ptr)
    {
    }

    Of course some would argue that it would only be fully compliant if used
    with the following *alloc functions:

    void *malloc(size_t size)
    {
    return NULL;
    }
    void *calloc(size_t nmemb, size_t size)
    {
    return NULL;
    }
    void *realloc(void *ptr, size_t size)
    {
    return NULL;
    }

    --
    Bertrand Mollinier Toublet
    "Reality exists" - Richard Heathfield, 1 July 2003
     
    Bertrand Mollinier Toublet, Jul 2, 2003
    #2
    1. Advertising

  3. Joona I Palaste

    asm_fool Guest

    Bertrand Mollinier Toublet <> wrote in message news:<bduv7u$vspvc$>...
    > Joona I Palaste wrote:
    > > asm_fool <> scribbled the following:
    > >
    > >>Where can I get the source code for the free() function according to
    > >>the latest standard?
    > >>Any URL reference please.

    > >
    > >
    > > There isn't "the source". The standard only specifies what the function
    > > should do, not how it should be implemented. This makes sense, as it
    > > does not tie C into one particular processor platform, but instead makes
    > > it a standard that can be adopted to just about every platform.
    > > If you really need the source code for free() on your particular
    > > implementation, ask in a newsgroup dedicated to that implementation.
    > >



    But there is no function definition.

    > Correct me if I am wrong, but wouldn't the following implementation
    > fully comply to the standard and be portable pretty much anywhere <g> ?
    >
    > void free(void *ptr)
    > {
    > }
    >
    > Of course some would argue that it would only be fully compliant if used
    > with the following *alloc functions:
    >
    > void *malloc(size_t size)
    > {
    > return NULL;
    > }
    > void *calloc(size_t nmemb, size_t size)
    > {
    > return NULL;
    > }
    > void *realloc(void *ptr, size_t size)
    > {
    > return NULL;
    > }
     
    asm_fool, Jul 3, 2003
    #3
  4. Joona I Palaste

    goose Guest

    Bertrand Mollinier Toublet <> wrote in message news:<bduv7u$vspvc$>...

    <snipped>

    > Correct me if I am wrong, but wouldn't the following implementation
    > fully comply to the standard and be portable pretty much anywhere <g> ?
    >
    > void free(void *ptr)
    > {

    if (ptr) { /* since we only ever return NULL from *alloc, this is UB */
    raise_demon (right_nostril);
    }
    > }
    >
    > Of course some would argue that it would only be fully compliant if used
    > with the following *alloc functions:
    >
    > void *malloc(size_t size)
    > {
    > return NULL;
    > }
    > void *calloc(size_t nmemb, size_t size)
    > {
    > return NULL;
    > }
    > void *realloc(void *ptr, size_t size)
    > {
    > return NULL;
    > }


    goose,
     
    goose, Jul 3, 2003
    #4
  5. goose <> scribbled the following:
    > Bertrand Mollinier Toublet <> wrote in message news:<bduv7u$vspvc$>...


    > <snipped>


    >> Correct me if I am wrong, but wouldn't the following implementation
    >> fully comply to the standard and be portable pretty much anywhere <g> ?
    >>
    >> void free(void *ptr)
    >> {

    > if (ptr) { /* since we only ever return NULL from *alloc, this is UB */
    > raise_demon (right_nostril);
    > }
    >> }


    No, AFAIK the standard says free(NULL) is a safe no-op.

    >> Of course some would argue that it would only be fully compliant if used
    >> with the following *alloc functions:
    >>
    >> void *malloc(size_t size)
    >> {
    >> return NULL;
    >> }
    >> void *calloc(size_t nmemb, size_t size)
    >> {
    >> return NULL;
    >> }
    >> void *realloc(void *ptr, size_t size)
    >> {
    >> return NULL;
    >> }


    --
    /-- Joona Palaste () ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/
    "You can pick your friends, you can pick your nose, but you can't pick your
    relatives."
    - MAD Magazine
     
    Joona I Palaste, Jul 3, 2003
    #5
  6. Joona I Palaste

    Scott Condit Guest

    Joona I Palaste wrote:
    > goose <> scribbled the following:
    >
    >>Bertrand Mollinier Toublet <> wrote in message news:<bduv7u$vspvc$>...

    >
    >
    >><snipped>

    >
    >
    >>>Correct me if I am wrong, but wouldn't the following implementation
    >>>fully comply to the standard and be portable pretty much anywhere <g> ?
    >>>
    >>>void free(void *ptr)
    >>>{

    >>
    >> if (ptr) { /* since we only ever return NULL from *alloc, this is UB */
    >> raise_demon (right_nostril);
    >> }
    >>
    >>>}

    >
    >
    > No, AFAIK the standard says free(NULL) is a safe no-op.


    And in that example, free (NULL) would be a safe no-op. ptr
    is tested.

    socode
     
    Scott Condit, Jul 3, 2003
    #6
  7. On Thu, 2 Jul 2003, asm_fool wrote:
    >
    > Bertrand Mollinier Toublet <> wrote in message news:<bduv7u$vspvc$>...
    > > Joona I Palaste wrote:
    > > > asm_fool <> scribbled the following:
    > > >
    > > >>Where can I get the source code for the free() function according to
    > > >>the latest standard?
    > > >
    > > > There isn't "the source". The standard only specifies what the function
    > > > should do, not how it should be implemented.


    > But there is no function definition.


    Snip irrelevant bits, and don't middle-post. Your comment doesn't make
    any sense in the context it's in. If you'd put it below Bertrand's
    function definition, then it would be more sensical - you'd simply be
    wrong. {} is a perfectly valid function body.

    > > Correct me if I am wrong, but wouldn't the following implementation
    > > fully comply to the standard and be portable pretty much anywhere <g> ?
    > >
    > > void free(void *ptr)
    > > {
    > > }


    Yup.

    -Arthur,
    but there is no spoon.
     
    Arthur J. O'Dwyer, Jul 3, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peri
    Replies:
    2
    Views:
    3,013
  2. Richard Bos

    Re: Source code for free() lib function

    Richard Bos, Jul 2, 2003, in forum: C Programming
    Replies:
    0
    Views:
    706
    Richard Bos
    Jul 2, 2003
  3. E. Robert Tisdale

    Re: Source code for free() lib function

    E. Robert Tisdale, Jul 3, 2003, in forum: C Programming
    Replies:
    1
    Views:
    1,666
    Hans-J. Boehm
    Jul 3, 2003
  4. Nick Keighley

    Re: Source code for free() lib function

    Nick Keighley, Jul 3, 2003, in forum: C Programming
    Replies:
    0
    Views:
    656
    Nick Keighley
    Jul 3, 2003
  5. karl malbrain

    Re: Source code for free() lib function

    karl malbrain, Jul 3, 2003, in forum: C Programming
    Replies:
    0
    Views:
    731
    karl malbrain
    Jul 3, 2003
Loading...

Share This Page