Thread: Following CTools

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    PUBLIC is a macro that probably expands to nothing - whilst PRIVATE or NONPUBLIC would expand to static (which means that code outside of the source is not able to link to that function).

    Code:
    if ( !(node = (LST_BUCKET*)malloc(size + sizeof(LST_BUCKET))) )
    If we didn't get the memory (node == NULL) then bail out - we CAN NOT continue here if we can't allocate memory.

    It is obviously a decision that depends on the type of application and several other circumstances, whether you for example just return NULL or abort the application (or for that matter, do something different). In small applications, I usually write a "bailout" function that takes a string as parameter, and does "exit(1)" after printing the string. Sometimes it's better to leave the decision whether to quit/continue to some other part of the code, which can for example tell the user in a better way that we couldn't store the data - maybe there is some other app that can be shut down to free some memory, for example?

    Yes, it's a void *, so it's returning a "pointer to anything and nothing" in the sense that it can point to anything, but you can't access that pointer until you turn it into something else.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #2
    Registered User
    Join Date
    Jun 2008
    Posts
    6
    thank you so much guys. that's extremely extremely helpful. Obviously (to you) this void = pointer to anything thing makes code for datastructres infinitely more reusable so it's very important

Popular pages Recent additions subscribe to a feed