473,597 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

typedef void foo_t()

How does typedef work for foo2_t?

What can one do with foo2_t?

------ bar.c ------
void foo() {}

typedef void (*foo1_t)();
typedef void foo2_t(); /* How does typedef work here? */

int main()
{
foo1_t foo1 = foo;
foo2_t foo2 = foo; /* Line 9 */
return 0;
}
-------------------

GNU gcc 4.0.1

bar.c: In function `main':
bar.c:9: error: function `foo2' is initialized like a variable
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Dec 9 '05 #1
4 2513
In article <dn**********@d omitilla.aioe.o rg>,
Alex Vinokur <al****@users.s ourceforge.net> wrote:
typedef void foo2_t(); /* How does typedef work here? */ ....foo2_t foo2 = foo; /* Line 9 */


This would be legal:

foo2_t *foo2 = foo;

-- Richard
Dec 9 '05 #2
Alex Vinokur said:
How does typedef work for foo2_t?

What can one do with foo2_t?

------ bar.c ------
void foo() {}

typedef void (*foo1_t)();
This means that

foo1_t x;

is a declaration that x is a pointer to a function taking unknown arguments
and returning void.
typedef void foo2_t(); /* How does typedef work here? */


This means that

foo2_t y;

is a declaration that y is a function taking unknown arguments and returning
void.

Because it's a function, it can't be instantiated in the same way an object
can. Nevertheless, this is a useful technique. If the topic cops can just
hold their fire for a second...

typedef LRESULT RJH_MESSAGE_HAN DLER(HWND,
UINT,
WPARAM,
LPARAM);

RJH_MESSAGE_HAN DLER DebuggerCreate;
RJH_MESSAGE_HAN DLER DebuggerDestroy ;
RJH_MESSAGE_HAN DLER DebuggerReset;
RJH_MESSAGE_HAN DLER DebuggerDisplay ;

is valid C, and (arguably) is neater than:

LRESULT DebuggerCreate( HWND, UINT, WPARAM, LPARAM);
LRESULT DebuggerDestroy (HWND, UINT, WPARAM, LPARAM);
LRESULT DebuggerReset(H WND, UINT, WPARAM, LPARAM);
LRESULT DebuggerDisplay (HWND, UINT, WPARAM, LPARAM);

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 9 '05 #3
Richard Heathfield <in*****@invali d.invalid> writes:
Alex Vinokur said:
How does typedef work for foo2_t?

What can one do with foo2_t?

------ bar.c ------
void foo() {}

typedef void (*foo1_t)();
This means that

foo1_t x;

is a declaration that x is a pointer to a function taking unknown arguments
and returning void.
typedef void foo2_t(); /* How does typedef work here? */


This means that

foo2_t y;

is a declaration that y is a function taking unknown arguments and returning
void.

Because it's a function, it can't be instantiated in the same way an object
can. Nevertheless, this is a useful technique. If the topic cops can just
hold their fire for a second...


I don't see anything in what you write that could be considered off topic, so
no need to ask the topic cops to shut up... (And I haven't written one single
line of code for windows apps in more than five years).
typedef LRESULT RJH_MESSAGE_HAN DLER(HWND,
UINT,
WPARAM,
LPARAM);

RJH_MESSAGE_HAN DLER DebuggerCreate;
RJH_MESSAGE_HAN DLER DebuggerDestroy ;
RJH_MESSAGE_HAN DLER DebuggerReset;
RJH_MESSAGE_HAN DLER DebuggerDisplay ;


Interesting. I've never used function declaration like these, and I agree that
they could be prefered in some situations...

/Niklas Norrthon
Dec 12 '05 #4
Niklas Norrthon said:
Richard Heathfield <in*****@invali d.invalid> writes:
typedef LRESULT RJH_MESSAGE_HAN DLER(HWND,
UINT,
WPARAM,
LPARAM);

RJH_MESSAGE_HAN DLER DebuggerCreate;
RJH_MESSAGE_HAN DLER DebuggerDestroy ;
RJH_MESSAGE_HAN DLER DebuggerReset;
RJH_MESSAGE_HAN DLER DebuggerDisplay ;


Interesting. I've never used function declaration like these, and I agree
that they could be prefered in some situations...

I forgot to say earlier that I actually prefer to typedef function types
rather than function pointer types, because:

void foo(RJH_MESSAGE _HANDLER *fptr)
{
... whatever ...
}

reminds me that I'm dealing with a pointer type. I don't like hiding
pointers with typedef. Just a style thing really.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 12 '05 #5

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

Similar topics

6
1903
by: Dave | last post by:
Hello all, I have included below a header file for a module I'm working on. Please note the line marked "***** ERROR HERE *****". At this line, the type dl_t is not being seen for some reason. Can anybody see why this is? Thanks, Dave
2
2339
by: PengYu.UT | last post by:
I have the following sample program, which can convert function object with 1 argument into function object with 2 arguments. It can also do + between function object of the same type. The last line is very long. I'm wondering if there is any way to suppress it. I can only think of typedef. But I'm not sure whether I can use typedef for the return type. Would you please help me? Please don't be daunted by the length of the code.
30
4230
by: stephen henry | last post by:
Hi all, I have a question that I'm having difficulty answering. If I have a struct: typedef struct my_struct_tag{ struct my_other_struct *other; } my_struct_tag
15
5643
by: Merrill & Michele | last post by:
typedef struct { WORD versionNumber; WORD offset; } MENUITEMTEMPLATEHEADER; This is from vol 5 of unnamed platform's programmer's reference. I could make this conforming by enclosing everything in a /*...*/ comment and appending the 'hail world' code. Is there an easier, and, let's say, more
9
5285
by: Juggernaut | last post by:
I am trying to create a p_thread pthread_create(&threads, &attr, Teste, (void *)var); where var is a char variable. But this doesnt't work, I get this message: test.c:58: warning: cast to pointer from integer of different size. Now I thought that when it was a void I could pass anything? Thing is it works when I use an int, but in this case I wanted to use a char. It wouldnt be hard to work around it, but it annoys me because I've heard...
16
3823
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
2
2921
by: Mehta Shailendrakumar | last post by:
Hi all, Have alook at two different declarations below: typedef unsigned char uc; typedef void (*fptr) (void); The first declaration has a left part which is a C keyword: "unsigned char" and the declaration is clarly understandable.
7
15265
by: Michael B Allen | last post by:
I have a forward reference like: struct foo; int some_fn(struct foo *param); Because the parameter is a pointer the compiler is satisfied. But now I wan to change 'struct foo' to a typedef'd type like 'foo_t'. The following all fail to compile:
15
2553
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! ) what is it supposed to do ?
0
7969
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8272
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...
1
8035
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
6688
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 project—planning, coding, testing, and deployment—without 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...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1238
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.