Somebody misunderstod me

S

SW1

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.
 
J

Jens.Toerring

SW1 said:
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
--
_ _____ _____
| ||_ _||_ _| (e-mail address removed)-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
 
M

Mark Gordon

On 16 Nov 2003 06:54:00 -0800
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?
 
R

Richard Heathfield

SW1 said:
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.
 
A

Alan Balmer

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top