943,987 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1272
  • C RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Oct 14th, 2009
0
Re: why use of size 0 or 1 array in structure for URI'S etc
Quote ...
Now this will crash.
An example that actually compiles would help your case.
Reputation Points: 1446
Solved Threads: 135
Practically a Master Poster
Tom Gunn is offline Offline
681 posts
since Jun 2009
Oct 14th, 2009
0
Re: why use of size 0 or 1 array in structure for URI'S etc
It's purely theoretical. You shouldn't have to compile it to see that it will crash.

The buffer will be filled with unknown data after the first two known values so the four bytes at BYTE *data will be some random value which surely will not be the desired pointer value.
The zero sized array version ->data member will always point to the next byte after the known values in the buffer.
SVR
Reputation Points: 10
Solved Threads: 4
Light Poster
SVR is offline Offline
44 posts
since May 2008
Oct 14th, 2009
0
Re: why use of size 0 or 1 array in structure for URI'S etc
Quote ...
You shouldn't have to compile it to see that it will crash.
All I see is undefined behavior from using a bogus pointer. I have debugged many cases where the same problem does not crash, so your theoretical result does not mean anything unless you can back it up with empirical data. The problem is that saying things like this will crash gives beginners a false sense of security that the program will fail spectacularly if they do something wrong. It is just as probable that the program will fail silently and continue running until the damage done is very costly.
Reputation Points: 1446
Solved Threads: 135
Practically a Master Poster
Tom Gunn is offline Offline
681 posts
since Jun 2009
Oct 14th, 2009
0
Re: why use of size 0 or 1 array in structure for URI'S etc
Click to Expand / Collapse  Quote originally posted by Tom Gunn ...
All I see is undefined behavior from using a bogus pointer. I have debugged many cases where the same problem does not crash, so your theoretical result does not mean anything unless you can back it up with empirical data. The problem is that saying things like this will crash gives beginners a false sense of security that the program will fail spectacularly if they do something wrong. It is just as probable that the program will fail silently and continue running until the damage done is very costly.
Agreed. Saying it will crash is highly subjective.

I will try to avoid that in the future. I forget that what's 'obvious' to me is not to every one
SVR
Reputation Points: 10
Solved Threads: 4
Light Poster
SVR is offline Offline
44 posts
since May 2008
Oct 14th, 2009
0
Re: why use of size 0 or 1 array in structure for URI'S etc
Quote ...
I forget that what's 'obvious' to me is not to every one
We all do. For me, obvious now is not always obvious later too.
Reputation Points: 1446
Solved Threads: 135
Practically a Master Poster
Tom Gunn is offline Offline
681 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: 2d-board algorithm: Total number of different moves to reach a location
Next Thread in C Forum Timeline: Adding 2 arrays together





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC