Re: reply the answer
- From: Harald van Dijk <truedfx@xxxxxxxxx>
- Date: Sat, 30 Jun 2007 22:25:00 +0200
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.
.
- References:
- reply the answer
- From: guthena
- Re: reply the answer
- From: Army1987
- Re: reply the answer
- From: Harald van Dijk
- Re: reply the answer
- From: CBFalconer
- Re: reply the answer
- From: Harald van Dijk
- Re: reply the answer
- From: CBFalconer
- reply the answer
- Prev by Date: Re: Machine epsilon: conclusion
- Next by Date: Re: Machine epsilon: conclusion
- Previous by thread: Re: reply the answer
- Next by thread: ctime \n rationale
- Index(es):
Relevant Pages
|
|