Type of expression

S

somenath

Hi All,

I got some questions regarding the type of expression .
For example

1)char *const *(*ptr)();
Here the type of ptr is it is constant pointer to a function which
accept unspecified number of argument and returns char *
2) char *const *(ptr1)();

But in this case ptr1 is without *(and it is compiling) but I am not
getting what will be the type of ptr1?

I would request if some body can suggest some easy way to deduce the
type of the particular variable

Regards,
Somenath
 
W

Walter Roberson

somenath said:
I would request if some body can suggest some easy way to deduce the
type of the particular variable

See if you can find a 'cdecl' program for your operating system.
 
V

vippstar

Hi All,

I got some questions regarding the type of expression .
For example

1)char *const *(*ptr)();
Here the type of ptr is it is constant pointer to a function which
accept unspecified number of argument and returns char *
2) char *const *(ptr1)();

But in this case ptr1 is without *(and it is compiling) but I am not
getting what will be the type of ptr1?

I would request if some body can suggest some easy way to deduce the
type of the particular variable
from right to left it becomes simple

it's a function named 'ptr1' that takes an unspecified number of
arguments and returns a pointer to const pointer to char.
It's the same with char * const * ptr1();
 
D

David Thompson

Hi All,

I got some questions regarding the type of expression .
For example

1)char *const *(*ptr)();
Here the type of ptr is it is constant pointer to a function which
accept unspecified number of argument and returns char *

No. pointer to function of unspecified arguments which returns pointer
to const pointer to char, or equivalently ... returns pointer to const
'char *'. But note that is a pointer to a const object (memory
location) containing a 'char *' which is itself a pointer to non-const
char, and not the same thing as a 'const char *' which is an object or
value which points to a const char (object). People often gloss over
this distinction, especially when talking or writing informally,
because _usually_ what is important about a pointer is whether it
points to const or nonconst, not whether the pointer itself is const
or nonconst if it is even in an object at all. But C supports both --
indeed all four, or in general all 2 up N combinations; plus the same
again for 'volatile' although that is much less used, and in C99 for
'restrict' although that probably isn't very widely used _yet_.

Also note 'const' isn't quite the same as 'constant'; depending on
context 'const' sometimes means an object isn't supposed to be
changed, and sometimes merely means it isn't supposed to be changed
_through this access (pointer)_, but in no case does it by itself
actually guarantee the object _can't_ change.
2) char *const *(ptr1)();

But in this case ptr1 is without *(and it is compiling) but I am not
getting what will be the type of ptr1?
This is (actual) function of unspecified args returning ptr to const
ptr to char, or as above returning ptr to const 'char *'.
I would request if some body can suggest some easy way to deduce the
type of the particular variable
'Declaration follows use.' If the operator-like tokens in a
declaration, and specifically in a declarator, were used in the same
pattern on the declared identifier in an expression, they would be
legal -- at least 'syntactically' (including constraints); things like
dereferencing a pointer whose value isn't currently valid,
subscripting with a value not in the actual bounds of the array (or
sometimes just past), etc. are semantically illegal.

char * x; // x is a pointer to char; assuming it is set to point to an
actual char, *x accesses that char

char * x [3]; // the expression *x[1] parses as *(x[1]) and therefore
the declaration does the equivalent: x is an array of 3 pointers to
char; x[1] accesses one of the pointers; assuming that pointer is set
to point to a char, *x[1] accesses that char.

char * x (); // x is a function of unspecified args returning a
pointer to char; if x (3) is a valid call (i.e. the function actually
accepts one int) and when executed x (3) returns a valid pointer to
char, * x (3) accesses that char

etc.

- formerly david.thompson1 || achar(64) || worldnet.att.net
 

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

Forum statistics

Threads
473,961
Messages
2,570,131
Members
46,689
Latest member
liammiller

Latest Threads

Top