Re: by ref parameter is just a syntax sugar?
From: James Dennett (jdennett_at_acm.org)
Date: 09/02/04
- Next message: James Dennett: "Re: by ref parameter is just a syntax sugar?"
- Previous message: Alwyn: "Re: by ref parameter is just a syntax sugar?"
- In reply to: Mike Wahler: "Re: by ref parameter is just a syntax sugar?"
- Next in thread: Mike Wahler: "Re: by ref parameter is just a syntax sugar?"
- Reply: Mike Wahler: "Re: by ref parameter is just a syntax sugar?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: James Dennett: "Re: by ref parameter is just a syntax sugar?"
- Previous message: Alwyn: "Re: by ref parameter is just a syntax sugar?"
- In reply to: Mike Wahler: "Re: by ref parameter is just a syntax sugar?"
- Next in thread: Mike Wahler: "Re: by ref parameter is just a syntax sugar?"
- Reply: Mike Wahler: "Re: by ref parameter is just a syntax sugar?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|