Somebody misunderstod me

Discussion in 'C Programming' started by SW1, Nov 16, 2003.

  1. SW1

    SW1 Guest

    Well, i think realloc should always work if you just make the
    buffersize smaller, and thats all I'm doing, if you look at it closely
    realloc can't ever make the memory bigger in my code (the IF statement
    does that). Well anyway I'm not having trouble with realloc, I have
    trouble fwriting and the strange thing is on my WinXP machine it works
    and on my Win2000 it doesn't. The only thing I wanted to know is if
    anybody encountered the same problem before, not what i've done wrong
    elsewhere in my Code, I don't care since it compiles alright and does
    everything i want, except fwrite!! A´nd one thing: there is a recv();
    function if you include winsock32 or sock (depending on which OS your
    coding). And one thing I would like to now, if there are any
    restrictions on fwrite, e.g. how many bytes you can write max. in one
    fwrite call. If it makes you guys happy then i build in error
    checking, and maybe your right and I'm wrong.

    One last thing, I think in any of human interactions you shouldn't
    offend others. Maybe there not as smart, or as good as you in
    something, but certainly you don't get much help from people you
    offend. And if your angry go somewhere else but don't offend people
    you don't even know, thats just cheap. I thought this group was about
    helping each other out, or sharing knowledge not being rude.

    Thanks to all who tried to be helpfull, and shame on the people who
    are just being rude.
     
    SW1, Nov 16, 2003
    #1
    1. Advertising

  2. SW1

    -berlin.de Guest

    SW1 <> wrote:
    > Well, i think realloc should always work if you just make the
    > buffersize smaller, and thats all I'm doing, if you look at it closely
    > realloc can't ever make the memory bigger in my code (the IF statement


    We're do you got the guarantee from that your implementation won't
    move the memory block when you use realloc() to decrease the blocks
    size? Perhaps a clever implementation sees that what remains of the
    block is surrounded by free memory and there's a free hole somewhere
    else where the block now would fit in nicely, so it moves the block
    in order to get a large continuous block of free memory. So, unless
    the standard explicitely forbids moving the block when you decrease
    the size you shouldn't rely on it.

    > does that). Well anyway I'm not having trouble with realloc, I have
    > trouble fwriting and the strange thing is on my WinXP machine it works
    > and on my Win2000 it doesn't. The only thing I wanted to know is if
    > anybody encountered the same problem before, not what i've done wrong
    > elsewhere in my Code, I don't care since it compiles alright and does


    That it compiles without obvious problems just means that you got
    the syntax right (or you managed to shut up he compiler), but
    nothing else. There still could be lots of bugs lurking in your
    program (and there often are in non-trivial programs).

    > everything i want, except fwrite!! And one thing: there is a recv();
    > function if you include winsock32 or sock (depending on which OS your


    What makes you so sure it hangs in fwrite()? Did you check with a
    debugger or did you add some lines to print out which statements
    actually are executed? Since you seem to loop getting two dots does
    not prove that it's fwrite(), perhaps it just fails the second time
    round. And the non-standard C function recv() looks much more like a
    potential point of failure - that's the one that probably could block
    if there's nothing to receive. But you won't find people discussing
    it here, because it's an extension to C, only people knowing about
    the way it's implemented in Win2000 or XP will be able to help you
    - so that's something you're going to have to discuss in a Microsoft
    related newsgroup.

    > coding). And one thing I would like to now, if there are any
    > restrictions on fwrite, e.g. how many bytes you can write max. in one


    There are no such restrictions.

    > fwrite call. If it makes you guys happy then i build in error
    > checking, and maybe your right and I'm wrong.


    It's not about making someone happy (expect perhaps you) but about
    figuring out what's going wrong.

    > One last thing, I think in any of human interactions you shouldn't
    > offend others. Maybe there not as smart, or as good as you in
    > something, but certainly you don't get much help from people you
    > offend. And if your angry go somewhere else but don't offend people
    > you don't even know, thats just cheap. I thought this group was about
    > helping each other out, or sharing knowledge not being rude.


    Simply don't get upset. Some people are less polite than others (and
    some might even be morons), if you can't stand this you better keep
    away from newsgroups. Only if all people are being rude to you you
    should get very careful, it usually means that *you* fucked up badly;-)

    Regards, Jens
    --
    _ _____ _____
    | ||_ _||_ _| -berlin.de
    _ | | | | | |
    | |_| | | | | | http://www.physik.fu-berlin.de/~toerring
    \___/ens|_|homs|_|oerring
     
    -berlin.de, Nov 16, 2003
    #2
    1. Advertising

  3. SW1

    Mark Gordon Guest

    On 16 Nov 2003 06:54:00 -0800
    (SW1) wrote:

    > Well, i think realloc should always work if you just make the
    > buffersize smaller,


    Well, you are wrong. Realloc *can* fail on making the buffer smaller or
    even on keeping it the same size. Realloc can also move the buffer on
    shrinking or staying the same size. There are even good reasons why
    these things may happen.

    > and thats all I'm doing, if you look at it closely
    > realloc can't ever make the memory bigger in my code (the IF statement
    > does that). Well anyway I'm not having trouble with realloc, I have
    > trouble fwriting and the strange thing is on my WinXP machine it works
    > and on my Win2000 it doesn't.


    Unless you are using XP specific APIs it is almost certainly nothing to
    do with the OS IMHO. You are probably invoking undefined behaviour and
    it just happens not to cause an obvious failure on your XP machine.

    > The only thing I wanted to know is if
    > anybody encountered the same problem before, not what i've done wrong
    > elsewhere in my Code, I don't care since it compiles alright and does
    > everything i want, except fwrite!!


    Without your code (no, I won't search for which thread you posted it in)
    I can say with a reasonable degree of confidence that if no one pointed
    out a problem with your fwrite the problem is somewhere else, so fix all
    the problems that have been pointed out to you and see where that gets
    you.

    > A´nd one thing: there is a recv();
    > function if you include winsock32 or sock (depending on which OS your
    > coding).


    Irrelevant. recv is not part of ISO C and so is off topic here. Also
    there are C implementations on machines without recv.

    > And one thing I would like to now, if there are any
    > restrictions on fwrite, e.g. how many bytes you can write max. in one
    > fwrite call. If it makes you guys happy then i build in error
    > checking, and maybe your right and I'm wrong.


    Since you don't know what is causing your problem how can you be certain
    it is not one of the things that has been pointed out to you?
    --
    Mark Gordon
    Paid to be a Geek & a Senior Software Developer
    Although my email address says spamtrap, it is real and I read it.
     
    Mark Gordon, Nov 16, 2003
    #3
  4. SW1 wrote:

    > Well, i think realloc should always work if you just make the
    > buffersize smaller,


    You're wrong. In theory at least, it can fail. And even if it doesn't fail,
    it can move the buffer. This is actually quite likely if the allocation
    subsystem is clever enough to realise it can fit the smaller block into a
    tidier space.

    > and thats all I'm doing, if you look at it closely
    > realloc can't ever make the memory bigger in my code (the IF statement
    > does that). Well anyway I'm not having trouble with realloc,


    You don't know that for sure.

    > I have
    > trouble fwriting and the strange thing is on my WinXP machine it works
    > and on my Win2000 it doesn't.


    Then it's broken. Fix the realloc. If it still doesn't work, repost and
    maybe someone here can help you out.

    > The only thing I wanted to know is if
    > anybody encountered the same problem before, not what i've done wrong
    > elsewhere in my Code, I don't care since it compiles alright and does
    > everything i want, except fwrite!! And one thing: there is a recv();
    > function if you include winsock32 or sock (depending on which OS your
    > coding). And one thing I would like to now, if there are any
    > restrictions on fwrite, e.g. how many bytes you can write max. in one
    > fwrite call.


    No, I don't think that's your problem.

    > If it makes you guys happy then i build in error
    > checking, and maybe your right and I'm wrong.


    The error checking won't hurt and might help.

    >
    > One last thing, I think in any of human interactions you shouldn't
    > offend others.


    Tom St Denis is a known troll, who appears (to me, at least) to be proud of
    his ability to use swear-words. He can be safely ignored.

    --
    Richard Heathfield :
    "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    K&R answers, C books, etc: http://users.powernet.co.uk/eton
     
    Richard Heathfield, Nov 16, 2003
    #4
  5. SW1

    Alan Balmer Guest

    On 16 Nov 2003 06:54:00 -0800, (SW1) wrote:

    >Well, i think realloc should always work if you just make the
    >buffersize smaller,


    You think wrongly, but you've already been told that.

    >and thats all I'm doing, if you look at it closely
    >realloc can't ever make the memory bigger in my code (the IF statement
    >does that). Well anyway I'm not having trouble with realloc, I have
    >trouble fwriting and the strange thing is on my WinXP machine it works
    >and on my Win2000 it doesn't.


    There's a pretty good chance that your misuse of realloc is causing
    your problems with fwrite. The kind of symptom you describe is often
    due to writing to memory you don't own. If realloc is moving the
    memory, you're probably clobbering the data or parameters passed to
    fwrite.

    In any case, I wouldn't bother to look further at your code until
    you've fixed the errors already pointed out.

    --
    Al Balmer
    Balmer Consulting
     
    Alan Balmer, Nov 17, 2003
    #5
    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. Peng Yu
    Replies:
    0
    Views:
    1,143
    Peng Yu
    Aug 14, 2003
  2. Alejandro Pombo
    Replies:
    0
    Views:
    468
    Alejandro Pombo
    Jan 25, 2006
  3. =?Utf-8?B?SmltIE1hY2U=?=

    Please, somebody help...

    =?Utf-8?B?SmltIE1hY2U=?=, Feb 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    287
    Trint Smith
    Feb 26, 2004
  4. =?Utf-8?B?TW9oYW1tYWQtUmV6YQ==?=

    Connecting ASP.NET to SQLServer,Somebody,Please!!

    =?Utf-8?B?TW9oYW1tYWQtUmV6YQ==?=, Apr 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    397
    Scott M.
    Apr 20, 2004
  5. =?Utf-8?B?TW9oYW1tYWQtUmV6YQ==?=

    Connecting ASP.NET to SQLServer,Somebody,Please!!

    =?Utf-8?B?TW9oYW1tYWQtUmV6YQ==?=, Apr 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    392
    =?Utf-8?B?UmFzaWthIFdpamF5YXJhdG5l?=
    Apr 21, 2004
Loading...

Share This Page