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
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!
>
> 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.
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.
Yup! Thanks. SHI^%
A function parameter is contained within file scope right?
Wrong!
--
Ian Collins.
ARGHRHGHGHH#!@$H@#$H@#H$@#H$H@#$H@#$H@$#
>>> 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.
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.
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.
;^(...
Thanks for not sticking me in your kill-file.
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.
;^)
I don't know why you think you would get put in anyone's killfile, but
regardless, I don't use one. :)
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"
>
> "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
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
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.
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
Thank you Sir.
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
Why?
--
Ian Collins.
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.
Good decision. Plonking the loser is a sensible thing to do.
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
At file scope, identifiers that begin with a single underscore are
reserved for use by the implementation.
--
Army1987 (Replace "NOSPAM" with "email")
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.