What's wrong with this code?

C

Chris Thomasson

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

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
 
C

Chris Thomasson

Keith Thompson said:
Chris Thomasson said:
_________________________________________________ [...]
_________________________________________________

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

Thad Smith

Ian said:
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.

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?
 
C

chandru.simple

_________________________________________________
#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.........
 
C

Chris Thomasson

Kenny McCormack said:
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.
 
A

Antoninus Twink


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

lawrence.jones

Thad Smith said:
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
 
A

Army1987

lawrence.jones said:
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.
At file scope, identifiers that begin with a single underscore are
reserved for use by the implementation.
 
R

Richard

Antoninus Twink said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top