Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What's wrong with this code?

0 views
Skip to first unread message

Chris Thomasson

unread,
Feb 10, 2008, 11:29:34 PM2/10/08
to
_________________________________________________
#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

Kenny McCormack

unread,
Feb 10, 2008, 11:25:36 PM2/10/08
to
In article <Vq-dnbYyMdmkUDLa...@comcast.com>,

Chris Thomasson <cri...@comcast.net> 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.

Chris Thomasson

unread,
Feb 10, 2008, 11:51:18 PM2/10/08
to

"Kenny McCormack" <gaz...@xmission.xmission.com> wrote in message
news:fooio0$baf$4...@news.xmission.com...

Yeah. That's my problem.

Chris Thomasson

unread,
Feb 11, 2008, 12:42:05 AM2/11/08
to

"Chris Thomasson" <cri...@comcast.net> wrote in message
news:e7idnQnzu4vMTzLa...@comcast.com...


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

YIKES!

Ian Collins

unread,
Feb 11, 2008, 1:08:25 AM2/11/08
to
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.

Harald van Dijk

unread,
Feb 11, 2008, 1:18:46 AM2/11/08
to

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.

Chris Thomasson

unread,
Feb 11, 2008, 1:27:37 AM2/11/08
to
"Ian Collins" <ian-...@hotmail.com> wrote in message
news:61a72pF...@mid.individual.net...

Yup! Thanks. SHI^%

Chris Thomasson

unread,
Feb 11, 2008, 1:38:00 AM2/11/08
to
"Harald van Dijk" <tru...@gmail.com> wrote in message
news:f3f9b$47afe8c6$541dfcd3$9...@cache6.tilbu1.nb.home.nl...

A function parameter is contained within file scope right?

Ian Collins

unread,
Feb 11, 2008, 1:30:31 AM2/11/08
to

Wrong!

--
Ian Collins.

Chris Thomasson

unread,
Feb 11, 2008, 1:39:47 AM2/11/08
to

"Ian Collins" <ian-...@hotmail.com> wrote in message
news:61a8c7F...@mid.individual.net...

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

Ian Collins

unread,
Feb 11, 2008, 1:34:01 AM2/11/08
to
Chris Thomasson wrote:
>
> "Ian Collins" <ian-...@hotmail.com> 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.

Harald van Dijk

unread,
Feb 11, 2008, 1:36:10 AM2/11/08
to
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.

Chris Thomasson

unread,
Feb 11, 2008, 1:46:41 AM2/11/08
to

"Chris Thomasson" <cri...@comcast.net> wrote in message
news:MdGdnXs8ms4gdjLa...@comcast.com...


file-scope {
#include <stdio.h>

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

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


When I look at that, I see _this existing not only within the function
parameter scope, but contained within the file-scope as well; this is source
of my confusion.

;^(...

Chris Thomasson

unread,
Feb 11, 2008, 1:49:59 AM2/11/08
to

"Harald van Dijk" <tru...@gmail.com> wrote in message
news:cb0d1$47afecda$541dfcd3$31...@cache1.tilbu1.nb.home.nl...

Thanks for not sticking me in your kill-file.

Chris Thomasson

unread,
Feb 11, 2008, 1:55:11 AM2/11/08
to

"Ian Collins" <ian-...@hotmail.com> wrote in message
news:61a8irF...@mid.individual.net...

Well, I don't like it when I made a massive screwed up like this. IMHO, I
would rather it be in the algorithm, not something fundamental within the C
Standard.

Here is the origin of my confusion:

http://groups.google.com/group/comp.programming.threads/msg/6ff53456a8e4dcfe

I am lucky if I don't get fired over this... I know I am going to hear about
it in the morning. LOL! I should go into work with egg already splattered
all over my face to save them some precious time and energy!

My threading skills keep me working.

;^)

Harald van Dijk

unread,
Feb 11, 2008, 1:48:28 AM2/11/08
to

I don't know why you think you would get put in anyone's killfile, but
regardless, I don't use one. :)

Keith Thompson

unread,
Feb 11, 2008, 2:56:04 AM2/11/08
to
"Chris Thomasson" <cri...@comcast.net> writes:
> _________________________________________________
> #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...

Others have already described the rules regarding identifiers
beginning with underscores. Briefly, there's all reserved in some
contexts; some are reserved in more contexts than others.

Your "_this", as it turns out, is used in a context in which that
particular form of identifier is not reserved -- in other words, your
code is ok as far as the standard is concerned.

Personally, though, I find it easier to avoid using identifiers
starting with underscores altogether than to remember the rules in
detail. Looking at your code, I have to stop and think for a moment
before remembering that it's ok in this case. If you had used an
identifier *not* starting with an underscore ("this_", if you like),
then your code would be just slightly easier to read.

Part of this, I suppose, is that I've never understood the rationale
for the rules as they exist, rather than just reserving all
identifiers starting with underscores for all purposes.

It's a matter of style, not of legality.

--
Keith Thompson (The_Other_Keith) <ks...@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Default User

unread,
Feb 11, 2008, 9:40:29 PM2/11/08
to
Chris Thomasson wrote:

>
> "Kenny McCormack" <gaz...@xmission.xmission.com> wrote in message
> news:fooio0$baf$4...@news.xmission.com...

> > 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.


One of the things you need to learn is that Kenny is troll. He will
tell any lie he can think of to cause trouble. The best information I
can give you on that score is to killfile or ignore him.


Brian

Peter Nilsson

unread,
Feb 11, 2008, 10:05:09 PM2/11/08
to
"Chris Thomasson" <cris...@comcast.net> 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...

Is that really the context? What do you hope to gain
by using a leading underscore in a parameter name?
Is it because you want to declare another 'this' in
the function body?

Other comments notwithstanding, note that _trailing_
underscores are perfectly legitimate. So what about
this_?

If your real reason is you want something close to 'this',
but don't want a C++ compiler to barf, then try 'thiz'.

--
Peter

Kenny McCormack

unread,
Feb 11, 2008, 10:36:34 PM2/11/08
to
In article <61cf8tF...@mid.individual.net>,

One of the things you need to learn is that the default loser is tard.
It will tell any lie it can think of to cause trouble. The best
information I can give you on that score is to killfile or ignore it.

Chris Thomasson

unread,
Feb 11, 2008, 11:50:01 PM2/11/08
to
>
"Peter Nilsson" <ai...@acay.com.au> wrote in message
news:86a90300-357c-4b8c...@s19g2000prg.googlegroups.com...

Yup. I don't want a C++ compiler to crap out on my me... IMHO, 'thiz' is
fairly clever/funny in this case; I just might use that! Thanks! Even
thought I might catch flavor of minor sarcastic hell in my shop... Something
akin to: Hey, the thread monkey can't spell! LOL!

:^D

Chris Thomasson

unread,
Feb 11, 2008, 11:58:12 PM2/11/08
to
"Keith Thompson" <ks...@mib.org> wrote in message
news:87tzkgl...@kvetch.smov.org...

> "Chris Thomasson" <cri...@comcast.net> writes:
>> _________________________________________________
[...]

>> _________________________________________________
>>
>> Is this non-portable?
>>
>> I am interested in the name of the variable...
>
> Others have already described the rules regarding identifiers
> beginning with underscores. Briefly, there's all reserved in some
> contexts; some are reserved in more contexts than others.
>
> Your "_this", as it turns out, is used in a context in which that
> particular form of identifier is not reserved -- in other words, your
> code is ok as far as the standard is concerned.
>
> Personally, though, I find it easier to avoid using identifiers
> starting with underscores altogether than to remember the rules in
> detail. Looking at your code, I have to stop and think for a moment
> before remembering that it's ok in this case. If you had used an
> identifier *not* starting with an underscore ("this_", if you like),
> then your code would be just slightly easier to read.
>
> Part of this, I suppose, is that I've never understood the rationale
> for the rules as they exist, rather than just reserving all
> identifiers starting with underscores for all purposes.
>
> It's a matter of style, not of legality.

Thank you Sir.

Thad Smith

unread,
Feb 12, 2008, 1:23:06 AM2/12/08
to

I find the wording of this restriction peculiar. If I say "this chair is
reserved for elderly people" I mean that anyone who is old may use the
chair. "This wine is reserved for a special occasion" means that it should
only be used on a special occasion.

By analogy, "identifiers that begin with a single underscore are reserved
for use as identifiers at file level" should mean that identifiers
beginning with a single underscore may only be used when they are
identifiers at file level.

Isn't language fun?

--
Thad

chandru...@gmail.com

unread,
Feb 12, 2008, 1:37:10 AM2/12/08
to
solution;
Here _this is Invalid Variable.........

Ian Collins

unread,
Feb 12, 2008, 1:41:02 AM2/12/08
to
chandru...@gmail.com wrote:
> On Feb 11, 9:29 am, "Chris Thomasson" <cris...@comcast.net> 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...
>>
> solution;
> Here _this is Invalid Variable.........

Why?

--
Ian Collins.

Chris Thomasson

unread,
Feb 12, 2008, 2:43:45 AM2/12/08
to

"Kenny McCormack" <gaz...@xmission.xmission.com> wrote in message
news:for482$7ks$1...@news.xmission.com...

plonk.

Antoninus Twink

unread,
Feb 12, 2008, 4:17:16 AM2/12/08
to
On 12 Feb 2008 at 7:43, Chris Thomasson wrote:
>
> "Kenny McCormack" <gaz...@xmission.xmission.com> wrote in message
> news:for482$7ks$1...@news.xmission.com...
>> In article <61cf8tF...@mid.individual.net>,
>> Default User <defaul...@yahoo.com> wrote:
>>>One of the things you need to learn is that Kenny is troll. He will
>>>tell any lie he can think of to cause trouble. The best information I
>>>can give you on that score is to killfile or ignore him.
>>
>> One of the things you need to learn is that the default loser is tard.
>> It will tell any lie it can think of to cause trouble. The best
>> information I can give you on that score is to killfile or ignore it.
>
> plonk.

You might like to look at a sample of Default Loser's posts from the
last year or so before jumping to conclusions.

Whatever someone thinks of Kenny, no fair-minded person could disagree
with his assessment of "Brian" and his complete absence of useful
contributions to this group.

Kenny McCormack

unread,
Feb 12, 2008, 6:25:13 AM2/12/08
to
In article <QZudnQego-6l0Sza...@comcast.com>,

Chris Thomasson <cri...@comcast.net> wrote:
>
>"Kenny McCormack" <gaz...@xmission.xmission.com> wrote in message
>news:for482$7ks$1...@news.xmission.com...
>> In article <61cf8tF...@mid.individual.net>,
>> Default User <defaul...@yahoo.com> wrote:
>>>Chris Thomasson wrote:
>>>
>>>>
>>>> "Kenny McCormack" <gaz...@xmission.xmission.com> wrote in message
>>>> news:fooio0$baf$4...@news.xmission.com...
>>>
>>>> > 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.
>>>
>>>
>>>One of the things you need to learn is that Kenny is troll. He will
>>>tell any lie he can think of to cause trouble. The best information I
>>>can give you on that score is to killfile or ignore him.
>>
>> One of the things you need to learn is that the default loser is tard.
>> It will tell any lie it can think of to cause trouble. The best
>> information I can give you on that score is to killfile or ignore it.
>
>plonk.
>

Good decision. Plonking the loser is a sensible thing to do.

lawrenc...@siemens.com

unread,
Feb 12, 2008, 2:01:59 PM2/12/08
to
Thad Smith <Thad...@acm.org> wrote:

> Ian Collins wrote:
>>
>> 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.
>
> I find the wording of this restriction peculiar. If I say "this chair is
> reserved for elderly people" I mean that anyone who is old may use the
> chair. "This wine is reserved for a special occasion" means that it should
> only be used on a special occasion.

I've never been particularly fond of that wording either, but I haven't
been able to come up with anything better. If you've got a suggestion,
I'd like to hear it.

-Larry Jones

I sure like summer vacation. -- Calvin

Army1987

unread,
Feb 13, 2008, 7:09:05 PM2/13/08
to
lawrence.jones wrote:

At file scope, identifiers that begin with a single underscore are
reserved for use by the implementation.

--
Army1987 (Replace "NOSPAM" with "email")

Richard

unread,
Feb 14, 2008, 12:07:40 PM2/14/08
to
Antoninus Twink <nos...@nospam.invalid> writes:

Surely telling people who to plonk, telling people they are off topic
and kissing Heathfield's ass are all rudimentary skills to joining the
CLC "regs" and saying "Indeed" on a regular basis? As they go Bwian has
worse than CBFalconer for uselessness here since he never actually
offers anything remotely "c-like" to the conversation.

0 new messages