Re: help with 'left-right' cdecl rule



jonsmallberries@xxxxxxxxx wrote:
In the FAQ they said to read from inside out. So yeah, this does make
sense foo is a const pointer to int.

This "const int * foo" also makes sense, foo is a pointer to a const
int.

But, "int const * foo" is just lame. I checked just for clarity's sake
to see if this is the same in C++ (it is) and the site had this to say.


It is the "const int * foo" version which is lame.
Reading from insde out, as you suggest:

const int * foo foo is a pointer to an int constant
int const * foo foo is a pointer to a constant int

"Basically 'const' applies to whatever is on its immediate left
other than if there is nothing there in which case it applies to
whatever is its immediate right)." Can we say confusing?

The "int const * foo" version obeys the first part of this rule,
the confusing exception is necessary to cover the case of
"const int * foo" .

.



Relevant Pages

  • Re: Funky function
    ... >> It makes it possible to call this member function on a const object ... >> object may or may not be const). ... int Data; ... in the next line you try to call a function foo on MyData. ...
    (comp.lang.cpp)
  • Re: Why is the pointer passed into the function still NULL?
    ... you must pass a *pointer* to the thing you want to modify. ... void foo (int x) ... The expression x in foo and the expression a in bar refer to ...
    (comp.lang.c)
  • Re: best idiom for freeing items from a list
    ... For two pointer types to be compatible, ... trying to define a generic comparison function, ... int my_intcmp(const int* i1, const int* i2) ...
    (comp.lang.c.moderated)
  • Re: Need some info on const char **
    ... I don't think the compiler will really like this (it could ... just says 'cast to pointer to const pointer of something ... right and tells me it's using 'int' as the default type. ... promises that foo will not change anything through ca. ...
    (comp.lang.c)
  • Re: Question about array declarators
    ... I found that the type of this declarator was "array of pointer to ... const int". ... type with "const int". ... The qualifiers on the type pointed at by fooare "const", the qualifiers on the type pointed at by &i are "". ...
    (comp.lang.c)