473,385 Members | 1,798 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,385 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 2301
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: 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...

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.