473,378 Members | 1,309 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,378 software developers and data experts.

typedef doubt

NG
Hi all,
can anybody explain me the following code snippet.

typedef void * (*VP)(char*);

VP vp;

thanks in advance
NG
Jul 22 '05 #1
5 1315
NG writes:
can anybody explain me the following code snippet.

typedef void * (*VP)(char*);

VP vp;


It says that VP can be used as a type identifier for a function that
receives a char * as a parameter and returns a void*.
Jul 22 '05 #2
NG posted:
Hi all,
can anybody explain me the following code snippet.

typedef void * (*VP)(char*);

VP vp;

thanks in advance
NG


VP is a new type. It is a pointer to a function. The
function is like so:

void* FunctionName(char*);

Say for instance you have an actual function:

void* MyFunction(char*)
{
return reinterpret_cast<void*>(52);
}

int main()
{
VP blah = MyFunction;

blah("j");
}
blah is now a pointer to a function.
-JKop
Jul 22 '05 #3
On Thu, 05 Aug 2004 10:51:13 -0700, NG wrote:
can anybody explain me the following code snippet.

typedef void * (*VP)(char*);

VP vp;


There is a tool under Linux (most unixes?) called cdecl, which is used
to explain or declare complex C and C++ types. I don't use it though :)

Using that tool with your declaration outputs

$ cdecl -+ explain 'void * (*VP)(char*);'

declare VP as pointer to function (pointer to char) returning
pointer to void

Having a typedef in your declaration changes the meaning of VP from
pointer to function to the alias of such a type.

We can use cdecl for the declaration of complex types. Using an example
from its man page:

$ cdecl -+ declare 'foo as pointer to member of class X function
(arg1, arg2) returning pointer to class Y'

class Y *(X::*foo)(arg1, arg2);

(Of course the 'class' keyword at the beginning is redundant in C++.)

Ali
Jul 22 '05 #4

"NG" <go******@gmail.com> wrote in message
news:64**************************@posting.google.c om...
Hi all,
can anybody explain me the following code snippet.

typedef void * (*VP)(char*);
Creates a name (an 'alias'), 'VP', for type
"pointer to function taking one type 'char*' argument
and returning type 'void*'".

Look up 'typedef' and 'function pointer' or 'pointer to function'
in a C++ text.
VP vp;


Creates an object of the above type (if this declaration
appears at file scope, also initializes it with a value of
NULL; if at block scope, the object is not given a meaningful
value).

-Mike
Jul 22 '05 #5
In message <5L******************@news.indigo.ie>, JKop <NU**@NULL.NULL>
writes
NG posted:
Hi all,
can anybody explain me the following code snippet.

typedef void * (*VP)(char*);

VP vp;

thanks in advance
NG


VP is a new type.


No. Despite its name, "typedef" does not define new types. VP is a new
name for an existing type (which, as it happens, didn't previously have
a name, unless you count "pointer to function taking pointer to char and
returning pointer to void").

--
Richard Herring
Jul 22 '05 #6

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

Similar topics

6
by: Fao | last post by:
Hi, I am in my first year of C++ in college and my professor wants me to Write a Program with multiple functions,to input two sets of user-defined data types: One type named 'Sign' declared by...
6
by: hercules | last post by:
Hi: In some code , I used typedef unsigned char BOOL; /*boolean */ But in other code , I must use typedef unsigned int BOOL; /* boolean */ How to remove the previous typedef ? ...
4
by: Thomas Matthews | last post by:
Hi, I'm writing code for an embedded system. In the system a Timer has 4 memory mapped registers of 32-bit lengths in contiguous locations: Timer 0: 0x1000 Configuration register 0x1004...
17
by: Steve Carter | last post by:
Can someone please explain why the following is not possible? typedef foobar { int x; foobar *next; /* why can't we do this? */ }; Thanks
5
by: Greg | last post by:
I can see there is no simple way to define a type like just a simple C++ typedef, such as typdef signaltype double; Using #define seems like a bad idea if it works atall. Using a struct...
4
by: subramanian100in | last post by:
Consider the program #include <iostream> using namespace std; class Test { public: Test(Test_int c_value)
2
by: Rufus | last post by:
Hi all, I have a problem with the next example code. I can't compile it without warnings with gcc. The compilation out is: $ gcc -Wall aPoint.c aPoint.c: In function 'printaPoint2':...
5
by: Ken Camann | last post by:
I was a bit surprised to find that my compiler (MSVC++) actually accepts the following as legal. It cleans up the code very nicely, but I am sort of confused about some of the finer points of how...
11
by: copx | last post by:
For some reason I cannot add a const qualifier to a typedefed pointer type if said type is used for a return value. It does work if the type is used for a parameter. I do not see the logic behind...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.