| | |
why use of size 0 or 1 array in structure for URI'S etc
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 33
Reputation:
Solved Threads: 4
0
#12 Oct 14th, 2009
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.
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.
0
#13 Oct 14th, 2009
•
•
•
•
You shouldn't have to compile it to see that it will crash.
-Tommy (For Great Justice!) Gunn
•
•
Join Date: May 2008
Posts: 33
Reputation:
Solved Threads: 4
0
#14 Oct 14th, 2009
•
•
•
•
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.
I will try to avoid that in the future. I forget that what's 'obvious' to me is not to every one
![]() |
Similar Threads
- size of array (C++)
- How to create a byte array/structure (C++)
- Size of array passed as parameter. (C++)
- Max size of Array (C++)
- how to increase the size of an array? (C)
Other Threads in the C Forum
- Previous Thread: 2d-board algorithm: Total number of different moves to reach a location
- Next Thread: Adding 2 arrays together
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory drawing dynamic executable fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer lazy license linked linkedlist linux linuxsegmentationfault list logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat openwebfoundation pattern pause pdf pointer pointers posix power problem program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming spoonfeeding stack standard strchr string strings structures student suggestions system test testautomation unix urboc user voidmain() win32api windows.h





