??? 05/26/10 22:46 Read: times |
#176211 - No, the string shall fit according to the C standard Responding to: ???'s previous message |
Jan Waclawek said:
Well, strings in C are one character longer than the number of characters within the "", as there is the null character automatically appended. Thus, you shall not try to initialize an a[4] array with "WD4-", as it won't fit. The compiler is kind enough to strip the extra null as it won't fit (so the result is what you expect); but it is also kind enough to warn about it.
If Keil won't warn about this, Keil is crap. JW Nothing nice about it. A four character string "WD4-" do fit in a four character array. The C standard says that the string "ABCD" may be stored as either 4 or 5 characters depending on available space. ยง6.7.8 item 14 of the C standard says: "An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array." |