if * was part of the type then
would give you 3 pointers, it IS part of the nameCode:foo* b, a, r;
Printable View
>> Although, I guess it would be just as easy to use the horizontal scroll bar to move over if it's indented a lot... Maybe that would ........ off the vi people enough to switch to a real IDE.
Yeah, I use a Scintilla-based IDE and it definitely has issues with horizontal scrolling (read: convulses). What do you use, by the way?
Oh great -- now we're talking about editors! :p
Usually KDevelop. Sometimes kate. Occasionally vim.
>> would give you 3 pointers, it IS part of the name
Tomorrow your going to wake up and realize that that doesn't make any sense.
EDIT:
>> would give you 3 pointers
Actually, that probably would have been a good way to implement it, from a language-design standpoint.
>> Sure it does. The only ptr will be the first one. What if you wanted 2, are you supposed to go
Well, OK. It kind of "straddles the fence" then, I guess. But I still wouldn't consider it part of the name.
Technically speaking, it's part of the declarator. A declgroup is formed of a single declspec, followed by one or more declarator-initializer groups. Everything that binds to the name (pointer, reference, array bounds, function arguments) is part of the declarator, while the bunch of keywords (typedef, friend, const, volatile, auto, static, extern, int, long, short, unsigned, signed, wchar_t, char, bool, float, double, class, struct, union) at the start is the declspec. The declspec combines with each of the declarator-initializer groups to form declarations.
>> Technically speaking, it's part of the declarator.
Well that settles then, I guess. :)
Being a pointer is part of the type. The * is part of the declarator that makes the declared entity be of pointer type. Or in other words, from a compiler writer's view, types are a property of variables and expressions, not of declarations.
In yet other words, compiler writers have a slightly different naming convention for code. In this:
most programmers would call "int *" the type. But to me, the only type here is "pointer to int", which is a property of the variable p. "int *" is just a part of the declaration of p.Code:int * p;
The way I was taught to look at it is this:
Kind of like you're declaring the dereferenced foo and bar as ints, from which implicitly follows that they're both of type pointer to int. Before someone explained it to me like this I was switching between the three styles as I couldn't decide which one made the most logical sense to me.Code:int *foo, *bar;
*foo is an int
*bar is an int