login
Header Space

 
 

Errors in desciption of asctime

November 8, 2007 - 2:11am
Submitted by Anonymous on November 8, 2007 - 2:11am.
KernelTrap

At the website

http://kerneltrap.org/man/linux/man3p/asctime.3p

there are following errors in the code:

static char wday_name[7][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static char mon_name[12][3] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};

The numbers [3] must be [4] since there is a '\0' character at the end.

Thomas

Not really. The code works,

November 8, 2007 - 7:36am
Anonymous (not verified)

Not really. The code works, and is correct. "%.3s" reads at most 3 bytes.

You are wrong. In C99 char

November 8, 2007 - 11:09am
Anonymous (not verified)

You are wrong.

In C99
char s[3] = "123";
is standards conformant and gives a 3-byte array without terminal '\0'.

You may be right but...

November 22, 2007 - 2:01am
Anonymous (not verified)

You may be right but some compilers generate an error:

Microsoft Visual C++ 2005 generates error C2117: "An array has too many initializers."
Reason: "No space for the null terminator in a string."

gcc version 3.4.4 generates "error: initializer-string for array of chars is too long"

Thomas

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
speck-geostationary