On Sunday 17 April 2005 12:22, Colin Carter wrote:
On Monday 18 April 2005 00:09, Jerry Feldman wrote:
On Sat, 16 Apr 2005 13:17:22 +1000
Colin Carter
wrote: Yes. In particular FORTRAN had a nice standard of first BYTE holding size.
Now it "appears" that C++ does not need to have this number because the string ends with a NULL (or strictly correct being a NUL. I hate
Bill Gates and mates just changing definitions.)
NULL is a macro in C referring to the null pointer. The string termination is simply a null byte, not NULL.
A macro you say! This I didn't know. I think of a NUL as being the ASCII character/byte being a full house of zero bits. The same as used at the end of a C string. You know, like ACK, BEL, HT, ETX, et cetera To make a FORTRAN character string acceptable to a C routine one might use: StringFred(1:6) = "Hello" // char(0) where // is the FORTRAN symbol for concatenate.
How does the C macro work?
Your perspective of the C string is by and large correct. In C macro and pre-processor defined value are interchangeable terms. Whatever is defined as NULL for your compiler ultimately translates to the value zero. NULL is most correctly used to describe a pointer value, but depending on it's context in the code, NULL could be used as a 0 value char, long, pointer, etc, though some compilers might cough up warnings about type conversions. Though there is really nothing wrong with it, most C code wouldn't terminate a string by stuffing NULL into a character position. (assuming char a[2] and char * b pointing to something usable...) a[0] = NULL; or *b = NULL; Instead you'll usually see: a[0] = '\0'; or *b = '\0'; [snip]