N
Nick Keighley
I am currently exploring the world of pointers and have encounter some
inconsistent information regarding the best way to reference an
array: array[1] OR *(array +1).
which is shortest and clearest? I'm much more of a fan of array
notation. Simple, clear and less typing. Modern compilers (anything in
the last 20 years or so) generate identical code anyway.
The only time I tend to use pointers is say picking a comms packet
apart.
pkt_ptr = &packet [0];
type = *pkt_ptr++;
length = (*pkt_ptr) * 256 + *pkt_ptr;
pkt_ptr += 2;
Each time you read a byte you advance the pointer you don't have to
keep track and count bytes yourself. So is the CRC field in byte 21 or
byte 22? Well it depends if the Qualifier option was selected.
One book says that you should not use the syntax array[1] because
of performance reason.
bad reason. It likely makes no difference.
1. write clear, correct code
2. test it thoughly
3. if its too slow make it faster
step 3 is not necessary far more often tahn many people imagine.
People often *start* at step 3. "wow that's /really/ fast, all you
have to do now is make it give the right answer!"
Another book says that the syntax array[1] is
only used by FORTRAN programmers who do not understand c pointers.
burn the book.
blacklist the place you bought it
tell your friends
hell, tell us! What was this book?
So
what is the true oh wizards? Does it make a difference?
WRITE SIMPLE CODE