Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

kernighan & ritchie weird prototype.

Status
Not open for further replies.

denc4

Programmer
Feb 17, 2005
107
0
0
NL
I found a piece of code in "The C programming language second edition ANSI C" which does not compile. Someone on this forum is bound to have it so i thought i'd post this question. It's on page 40 at the bottom. For the one's who don't have it:
The const declaration can also be used with array arguments, to indicate that the function does not change that array:

int strlen(const char[]);

The result is implementation-defined if an attempt is made to change a const.
As expected, my compiler complains:

error C2055: expected formal parameter list, not a type list

It wants the name of a local variable, not just char[]. Am i missing something? Or is the book wrong.. which i doubt.
 
Seems to work with Code Warrior. Which C compiler & OS are you using.
 
it does work, i forgot that prototypes don't necessarily need argument names.

i compiled it like this:
Code:
int strlen(const char[]);

main()
{
  return 0;
}

int strlen(const char s[])
{
  return 0;
}
The prototype is legal, the function head would be illegal without the "s" argument name. The "s" was not present on my previous attempt...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top