Re: by ref parameter is just a syntax sugar?

From: James Dennett (jdennett_at_acm.org)
Date: 09/02/04


Date: Wed, 01 Sep 2004 20:06:27 -0700

Mike Wahler wrote:
> "Thomas Matthews" <Thomas_MatthewsSpitsOnSpamBots@sbcglobal.net> wrote in
> message news:YIkZc.10206$FV3.115@newssvr17.news.prodigy.com...
>
>>Mike Wahler wrote:
>>
>>
>>>"Thomas Matthews" <Thomas_MatthewsSpitsOnSpamBots@sbcglobal.net> wrote
>
> in
>
>>>message news:jz0Zc.390$4l.266@newssvr15.news.prodigy.com...
>>>
>>>
>>>>2.4. Never declare or define variables inside a function
>>>> call.
>>>
>>>
>>>What does that mean?
>>>
>>>-Mike
>>>
>>>
>>
>>Here is an example:
>>void PrintValue(int value)
>>{
>> printf("Value: %d\n", value);
>> return;
>>}
>>
>>/* Here is an example of a declaration in a function call. */
>>int main(void)
>>{
>> PrintValue(int myValue = 7);
>
>
> This is not a function call, it's a prototype (i.e. a
> declaration).

It's neither; there's no return type.

> Are you saying that one should not
> use declarations inside a function definition?

I'd say that.

> If so, why not?

In C, because there's no type-safe linkage, so any
extern function declarations need to live in header
files to make the compiler check arguments in calls.

In both C and C++, because inside a function is not
a sane place to define an interface between that
function and a component defined outside of that
function.

>
>
>> return 0;
>>}
>
>
> The only function call above is to 'printf()'.
>
>
>>I believe that this syntax is not allowed in C,
>
>
> No.
>
>
>>but
>>allowed in C++;
>
>
> Yes, it's a function declaration with a default parameter.

No; no return type was specified. It's illegal in both
C and C++. If a return type is specified it's legal in
C++, but it's then not an example of declaring a variable
in a function call. There's no way to do such a thing
in either language.

-- James.



Relevant Pages

  • Re: Urgent C Questions
    ... int, not void. ... Then you need to turn up the warning level on QuickC. ... 3  missing prototype for 'main' ... stdio.h contains the declaration for printf: ...
    (comp.lang.c)
  • Re: Vigenere Cipher
    ... The fact that stats() is in Polish and that you haven't ... This declaration as good as nothing. ... > void deszyfruj(); ... Better spell it out: int main. ...
    (comp.lang.c)
  • Re: General question
    ... declaration for, it assumed that it was a function returning an int ... The first true C standard, ANSI/ISO of 1989 and 1990, changed things. ... Its prototype is: ...
    (comp.lang.c)
  • Re: Why is this not an error in Visual C?
    ... extern int foo; ... relative to the prototype declaration. ... that prototype is undefined behavior; ... it may be an extension of behavior for better diagnostics. ...
    (comp.lang.c)
  • compiling kernel
    ... scripts/kconfig/qconf.h:51: error: `e' was not declared in this scope ... scripts/kconfig/qconf.h:73: error: `int updateList' redeclared as different ... scripts/kconfig/qconf.h:8: error: forward declaration of `class ConfigList' ... ConfigLineEdit' ...
    (alt.os.linux.suse)