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

Typedef'ing a function

Is the following a legal typedef? (gcc -Wall -ansi -pedantic says it's ok)

typedef void Callback(void *obj);

I mean "a Callback is a function taking void * and returning void" (not
"a pointer to function"). Then of course I would use pointers to
Callback, like

void apply(Callback *f, void *a[], size_t size)
{
size_t i;

for (i = 0; i < size; i++)
f(a[i]);
}

I prefer it to

typedef void (*Callback)(void *obj);

because I don't like hiding pointers behind typedefs.
Nov 14 '05 #1
2 2303
Enrico Porreca <ep******@people.it> wrote:
Is the following a legal typedef? (gcc -Wall -ansi -pedantic says it's ok) typedef void Callback(void *obj); I mean "a Callback is a function taking void * and returning void" (not
"a pointer to function"). Then of course I would use pointers to
Callback, like void apply(Callback *f, void *a[], size_t size)
{
size_t i; for (i = 0; i < size; i++)
f(a[i]);
} I prefer it to typedef void (*Callback)(void *obj); because I don't like hiding pointers behind typedefs.


Yes (to the typedef) and yes (to its use).

The typedef declaration could be shortened to:
typedef void Callback(void *);
(ie. you don't have to name the parameter).

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #2

"S.Tobias" <si***@FamOuS.BedBuG.pAlS.INVALID> wrote

The typedef declaration could be shortened to:
typedef void Callback(void *);
(ie. you don't have to name the parameter).

Though normally it is a good idea.

typedef void PixelPutter(int, int, int);
typedef void PixelPutter(int x, int y, int colour);
Nov 14 '05 #3

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

Similar topics

1
by: James Aguilar | last post by:
Hey all, I ran into an interesting little problem with defining an iterator in a custom array class the other day. It goes something like this: template <typename T> class Array { public:...
3
by: James Aguilar | last post by:
Hey all, Another creative question: is it possible to do something like this to type define a pointer to a specific type of function: typedef bool (*)(std::string::const_iterator,...
3
by: Generic Usenet Account | last post by:
This is a two-part question. (1) I have implemented a "Datastructure Registry" template class. I am getting no compiler warnings with older compilers, but newer compilers are generating the...
5
by: Cancerbero | last post by:
Hi (first, excuse me for my bad english) As I know, the semantics for typedef is: typedef A B; I think this makes B a synonym of A, where A is an existing data type. Is that right? Based...
0
by: Enrico Porreca | last post by:
Is the following a legal typedef? (gcc -Wall -ansi -pedantic says it's ok) typedef void Callback(void *obj); I mean "a Callback is a function taking void * and returning void" (not "a pointer...
4
by: =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?= | last post by:
Hello. It's been about a year since I last did some C++ programming. I am now paying the price as I try to catch up with it. The following is the initial snippet of a simple program I am...
13
by: William Xu | last post by:
This won't compile: ,---- | int foo(char *p) | {} | | int main(int argc, char *argv) | { | typedef int (*FUNC)(void *); |
6
Markus
by: Markus | last post by:
Are there any major differences between the following, apart from syntactically: typedef struct { /** Struct members */ } stack; struct sstack { /** Struct members */ } stack;
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...
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:
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...
0
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...

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.