473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Type of expression

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
Jan 3 '08 #1
3 1810
In article <8d**********************************@e23g2000prf. googlegroups.com>,
somenath <so*********@gmail.comwrote:
>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.
--
"All is vanity." -- Ecclesiastes
Jan 3 '08 #2
On Jan 3, 12:18 pm, somenath <somenath...@gmail.comwrote:
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();
Jan 3 '08 #3
On Thu, 3 Jan 2008 02:18:58 -0800 (PST), somenath
<so*********@gmail.comwrote:
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
Jan 14 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Yuriy Solodkyy | last post by:
Hi VS 2005 beta 2 successfully compiles the following: using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program {
13
by: fctk | last post by:
hello is it possible to determine the type of an expression? something like operator sizeof but for types... for example: typeof(5.0) --> returns "double" typeof(5+7) --> returns "int"
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
15
by: Alex Vinokur | last post by:
Why does one need to use two kinds of sizeof operator: * sizeof unary-expression, * sizeof (type-name) ? Their behavior seem not to be different (see an example below). ------ C++ code...
3
by: mario | last post by:
Hi! First of all, sorry for my English, it's not my native tongue. Anyway, here we go: suppose I create a class that handles my own custom text strings. No, suppose I create TWO such classes,...
6
by: Protoman | last post by:
Read this code I found on the Internet: Object o,*oo; // Some objects int (Object::*ptr_to_o_func)(double); // ptr_to_obj_func is a pointer to a // member function of Object oo =...
1
by: urkel | last post by:
Hi everyone, I critically need help to solve this problem related to pointer in C++ Basically, I have a C/C++ program "retardselfenerg" calling a Fortran 90 subroutine "surfGF4.f90". i am so...
5
by: not_a_commie | last post by:
It seems that the only way to construct a struct from a type is to use Activator.CreateInstance. Is that true? Can anyone improve (performance-wise) upon this function below: /// <summary>...
3
by: bob_jenkins | last post by:
In C# 2.0, given an arbitrary expression and the types of the variables referenced in it, how do I find the expression type? For example, int x; float y; what is the type of x+y? If I had...
2
by: Ranganath | last post by:
Hi, Why is there a restriction that only integral types can be made static constant members of a class? For e.g., class B { private: static const double K = 10; };
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.