473,772 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1827
In article <8d************ *************** *******@e23g200 0prf.googlegrou ps.com>,
somenath <so*********@gm ail.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...@gm ail.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*********@gm ail.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.ne t
Jan 14 '08 #4

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

Similar topics

27
5638
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
1637
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
26212
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
15
2246
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 ------ #include <iostream> using namespace std;
3
1595
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, which differ e.g. in the characters mappings and in the implementation, etc... Necessary operators are overloaded, so that the following example works as one may intuitively expect it to work:
6
1561
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 = getObjectPtr(); ptr_to_o_func = (//some boolean condition) ?
1
23431
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 doubtful if my definitions of pointer variables and their use in calling function are correct. #include<bla bla bla......h> #include<bla bla bla.h> double surfGF4_(double*, double*, double*, double*, double*, double*, double*, double*, double*); ...
5
3271
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> /// Create an object of the given type /// A default constructor is required to be successful. /// A failure will return null. /// </summary>
3
1749
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 values for x and y, I could do (x+y).GetType(). But I don't, I just have their types. Default values won't work because values that don't cause the expression to raise an error might be very hard
2
2484
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
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.