Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > What's wrong with this code?

Reply
Thread Tools

What's wrong with this code?

 
 
Kenny McCormack
Guest
Posts: n/a
 
      02-11-2008
In article <(E-Mail Removed)>,
Chris Thomasson <(E-Mail Removed)> wrote:
>_______________________________________________ __
>#include <stdio.h>
>
>void foo(int _this) {
> printf("%d\n", _this);
>}
>
>int main(void) {
> foo(1);
> getchar();
> return 0;
>}
>
>_______________________________________________ __
>
>
>
>Is this non-portable?
>
>
>I am interested in the name of the variable...


Sometime in the next 15 minutes, one of the "regulars" will come on and
tell you that identifiers beginning with underscores are reserved for
the implementation.

 
Reply With Quote
 
 
 
 
Chris Thomasson
Guest
Posts: n/a
 
      02-11-2008
_________________________________________________
#include <stdio.h>

void foo(int _this) {
printf("%d\n", _this);
}

int main(void) {
foo(1);
getchar();
return 0;
}

_________________________________________________



Is this non-portable?


I am interested in the name of the variable...


--
Chris M. Thomasson
http://appcore.home.comcast.net
 
Reply With Quote
 
 
 
 
Chris Thomasson
Guest
Posts: n/a
 
      02-11-2008

"Kenny McCormack" <(E-Mail Removed)> wrote in message
news:fooio0$baf$(E-Mail Removed)...
> In article <(E-Mail Removed)>,
> Chris Thomasson <(E-Mail Removed)> wrote:
>>________________________________________________ _
>>#include <stdio.h>
>>
>>void foo(int _this) {
>> printf("%d\n", _this);
>>}
>>
>>int main(void) {
>> foo(1);
>> getchar();
>> return 0;
>>}
>>
>>________________________________________________ _
>>
>>
>>
>>Is this non-portable?
>>
>>
>>I am interested in the name of the variable...

>
> Sometime in the next 15 minutes, one of the "regulars" will come on and
> tell you that identifiers beginning with underscores are reserved for
> the implementation.


Yeah. That's my problem.

 
Reply With Quote
 
Chris Thomasson
Guest
Posts: n/a
 
      02-11-2008

"Chris Thomasson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
>
> "Kenny McCormack" <(E-Mail Removed)> wrote in message
> news:fooio0$baf$(E-Mail Removed)...
>> In article <(E-Mail Removed)>,
>> Chris Thomasson <(E-Mail Removed)> wrote:
>>>_______________________________________________ __
>>>#include <stdio.h>
>>>
>>>void foo(int _this) {
>>> printf("%d\n", _this);
>>>}
>>>
>>>int main(void) {
>>> foo(1);
>>> getchar();
>>> return 0;
>>>}
>>>
>>>_______________________________________________ __
>>>
>>>
>>>
>>>Is this non-portable?
>>>
>>>
>>>I am interested in the name of the variable...

>>
>> Sometime in the next 15 minutes, one of the "regulars" will come on and
>> tell you that identifiers beginning with underscores are reserved for
>> the implementation.

>
> Yeah. That's my problem.



In was under the impression that only a typename, function name, or #define
could
not use a leading underscore.

YIKES!

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      02-11-2008
Chris Thomasson wrote:

>
> In was under the impression that only a typename, function name, or
> #define could
> not use a leading underscore.
>

You should check the standard!

All identifiers that begin with a double underscore or an underscore
followed by a capital letter are reserved for any use.

Identifiers that begin with a single underscore reserved for use as
identifiers at file level.

--
Ian Collins.
 
Reply With Quote
 
Harald van Dijk
Guest
Posts: n/a
 
      02-11-2008
On Mon, 11 Feb 2008 19:08:25 +1300, Ian Collins wrote:
> Chris Thomasson wrote:
>> In was under the impression that only a typename, function name, or
>> #define could
>> not use a leading underscore.
>>

> You should check the standard!
>
> All identifiers that begin with a double underscore or an underscore
> followed by a capital letter are reserved for any use.
>
> Identifiers that begin with a single underscore reserved for use as
> identifiers at file level.


Right, so a function parameter named _this does not break any of the
rules, since a function parameter does not have file scope. So long as
it's not renamed to __this, it's fine.
 
Reply With Quote
 
Chris Thomasson
Guest
Posts: n/a
 
      02-11-2008
"Ian Collins" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Chris Thomasson wrote:
>
>>
>> In was under the impression that only a typename, function name, or
>> #define could
>> not use a leading underscore.
>>

> You should check the standard!
>
> All identifiers that begin with a double underscore or an underscore
> followed by a capital letter are reserved for any use.





>
> Identifiers that begin with a single underscore reserved for use as
> identifiers at file level.


Yup! Thanks. SHI^%

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      02-11-2008
Chris Thomasson wrote:
> "Harald van Dijk" <(E-Mail Removed)> wrote in message
> news:f3f9b$47afe8c6$541dfcd3$(E-Mail Removed)1.nb. home.nl...
>> On Mon, 11 Feb 2008 19:08:25 +1300, Ian Collins wrote:
>>> Chris Thomasson wrote:
>>>> In was under the impression that only a typename, function name, or
>>>> #define could
>>>> not use a leading underscore.
>>>>
>>> You should check the standard!
>>>
>>> All identifiers that begin with a double underscore or an underscore
>>> followed by a capital letter are reserved for any use.
>>>
>>> Identifiers that begin with a single underscore reserved for use as
>>> identifiers at file level.

>>
>> Right, so a function parameter named _this does not break any of the
>> rules, since a function parameter does not have file scope. So long as
>> it's not renamed to __this, it's fine.

>
> A function parameter is contained within file scope right?


Wrong!

--
Ian Collins.
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      02-11-2008
Chris Thomasson wrote:
>
> "Ian Collins" <(E-Mail Removed)> wrote in message
>> Chris Thomasson wrote:


>>> A function parameter is contained within file scope right?

>>
>> Wrong!

>
> ARGHRHGHGHH#!@$H@#$H@#H$@#H$H@#$H@#$H@$#


Having problems with the shift key

--
Ian Collins.
 
Reply With Quote
 
Harald van Dijk
Guest
Posts: n/a
 
      02-11-2008
On Sun, 10 Feb 2008 22:38:00 -0800, Chris Thomasson wrote:
> A function parameter is contained within file scope right?


Would you expect this to compile?

int foo(int bar) { return bar; }
int main(void) { return bar; }

I wouldn't. The scope of bar should and does end when the definition of
foo ends. That's not file scope.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Have I bought wrong product? enquirer Wireless Networking 2 06-10-2005 10:59 PM
Zero Config keeps connecting to the wrong AP =?Utf-8?B?ZGdyaWZmaXRo?= Wireless Networking 2 03-04-2005 05:52 PM
Is XML Doc wrong or is Schema wrong? (or both) Matthew XML 7 01-07-2005 10:05 PM
wrong connection status Peter Welk Wireless Networking 0 12-22-2004 03:26 PM
XP SP2 Wrong IP on connection D Wells Wireless Networking 3 12-09-2004 03:35 AM



Advertisments