Re: reply the answer



CBFalconer wrote:
Harald van D?k wrote:
CBFalconer wrote:
Harald van D?k wrote:
Army1987 wrote:
[...]
if (puts("HELLOWORLD !") < 0)
[...]
In C90, you don't strictly
need a prototype for puts() because it returns int and has no
"strange" arguments.

You do, however, need to make sure you pass an argument of type
const char *, not char *.

if (puts((const char *) "HELLOWORLD !") < 0)

There is a special exception for function calls where no
prototype is in scope that says it is okay to pass an argument
of type char * when the function accepts const char * (any
pointer to any character type or void) but it only applies to
functions whose /definition/ also doesn't include a prototype.
Whether the definition of puts includes a prototype is not
specified by the C standard.

Bushwah. There is no need to supply a const parameter to puts.
All the 'const' in the function prototype says is that the function
will not alter the passed parameter. I suspect you are thinking
C++, which is different.

I am not thinking of C++, I am thinking of C. I'm quoting from
n1124; I don't believe C90 was any different in this regard.
Calls to functions without a prototype in scope are described in
6.5.2.2p6, which contains

"If the function is defined with a type that includes a prototype,
and [...] the types of the arguments after promotion are not
compatible with the types of the parameters, the behavior is
undefined."

There are other provisions. I can't find them just now, but I
believe the following is indicative:

It is not. "Compatible type" is defined in 6.2.7. char * is not compatible
with const char *. If you have a concrete claim that it is, or that the
fact that the standard explicitly states the behaviour is undefined does
not mean the behaviour really is undefined, please share.
.



Relevant Pages

  • Re: reply the answer
    ... need a prototype for putsbecause it returns int and has no ... "strange" arguments. ... function accepts const char * ... Whether the definition of puts includes a prototype is not ...
    (comp.lang.c)
  • Re: reply the answer
    ... prototype is in scope that says it is okay to pass an argument ... of type char * when the function accepts const char * (any ... Whether the definition of puts includes a prototype is not ... don't believe C90 was any different in this regard. ...
    (comp.lang.c)
  • Re: gcc: pointer to array
    ... therefore at that point the expression "foo" has a function type ... without a prototype. ... I don't see any ambiguity here. ... const char *pc; ...
    (comp.lang.c)
  • Re: reply the answer
    ... prototype is in scope that says it is okay to pass an argument ... of type char * when the function accepts const char * (any ... Whether the definition of puts includes a prototype is not ... There is no need to supply a const parameter to puts. ...
    (comp.lang.c)
  • Re: Sort of mystified from an earlier thread
    ... *f but that's a const char. ... >complain about the difference between 'int' and 'char'? ... A similar thing happens during argument passing, since the prototype ... Greg Comeau / Celebrating 20 years of Comeauity! ...
    (comp.lang.c)