How would you interpret this...

This is a discussion on How would you interpret this... within the C Programming forums, part of the General Programming Boards category; This is for a library dealing with extendable strings. One of the functions I am to write says the following, ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    111

    How would you interpret this...

    This is for a library dealing with extendable strings.

    One of the functions I am to write says the following,

    ---start cut---
    void XstrFree(Xstr x)
    frees the extendable string pointed to by x, which must have the following properties:

    1. Must not be NULL
    2. Must have been originally returned from a call on one of the "creating" functions (lists the 3 creating functions)
    3. Must not have already been freed by passing it a call of XstrFree()

    If any of those requirements are not met, that is an error and the result of the call on XtrFree() is undefined.
    ---end cut---


    I know 1 and 3 can be dealt with in checking to see of malloc !== NULL, but I am a little confused with #2. I am thinking that #2 follows the following "math" 1 <=> 2 <=> 3. Would I be correct to assume that? I do not see how the free() could be returned form the creating functions, since those functions return a "new extendable string" for each.

    And also I'm curious on how the line of "In any of those..." can be interpreted. Meaning, just let the program crash if those three conditions are not met?

    Code:
    psdo
    if (1 || 2 || 3) free(myMallocString);
    else //let program crash and burn
    Last edited by Strahd; 09-23-2011 at 10:33 PM. Reason: changed malloc !== 0 to malloc !== NULL

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You are pretty much making all of the assumptions free does. (Except for the part about NULL, that won't break free.) So unless you are specifically keeping track some place of all the values assigned to whatever allocates, then just free it as you normally would. If you are actually tracking that type of stuff, see if it was something you actually allocated. If not, ignore it (or whatever it is you're doing for errors).


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    111
    Ahh ok so in short, make sure all the malloc calls ->I<- made are freed.

    Pretty much for errors it is, if it happens on our end, handle it (prints to stderr and exit(100)), if we didn't make it, "not my problem," which admittedly is a little hard for me do it (seems kinda cold).

    TY quzah

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    What operating system is this for... or is it to be multi-platform?

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    111
    Quote Originally Posted by CommonTater View Post
    What operating system is this for... or is it to be multi-platform?
    I cannot answer those questions, for it was not stated. This is an assignment. The computers, we are using are UNIX machines, we telenet into the computers.

    I figured what my problem was, by what Quzah said the light clicked on. My problem right now is I need to lay this program to rest for the night and get back at it tomorrow when my mind is rested. :S
    Last edited by Strahd; 09-23-2011 at 11:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read file line by line and interpret them
    By sombrancelha in forum C Programming
    Replies: 8
    Last Post: 03-17-2011, 10:48 AM
  2. Write a program to interpret roman numerals
    By unwanted in forum C Programming
    Replies: 2
    Last Post: 03-02-2011, 08:33 AM
  3. java question, how do you interpret this question.
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 11-02-2006, 10:30 AM
  4. C++ Casting (re-interpret cast)
    By Davros in forum C++ Programming
    Replies: 21
    Last Post: 07-20-2004, 04:53 PM
  5. How does hardware interpret data?
    By Silvercord in forum Tech Board
    Replies: 3
    Last Post: 01-29-2003, 01:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21