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

cyclic references of types

Hi,

I want to use a pointer to a methode that has a struct (i2cmessage_t) as a
parameter. This struct should have the pointer to the previously defined
methode as one of its members.
The code is below.

typedef void (*i2c_callback) (i2cmessage_t);

typedef struct{
slaveAddress_t slaveAddress;
uint8_t * sendBuffer;
uint8_t sendBufferLength;
uint8_t * receiveBuffer;
uint8_t receiveBufferLength;
i2c_callback callbackFunction;
} i2cmessage_t;

when I compile this code, gcc (actualy avr-gcc) generates a warning:
"parameter names (without types) in function declaration"
Obviously, this is not going to work.

How do I declare both types and have them refer to eachother. Is it
posible to write a forward declaration of a type or something?

Thanks in advanced.
grz,
Onno
Aug 3 '06 #1
7 1529
Onno writes:

Onno <de*******@gorgoz.orgwrites:
I want to use a pointer to a methode that has a struct (i2cmessage_t)
as a parameter. This struct should have the pointer to the previously
defined methode as one of its members.
'struct foo;' predeclares a struct. But you can't do the same with
typedefs. So,

Prepend:

typedef struct i2cmessage_s i2cmessage_t;
typedef void (*i2c_callback) (i2cmessage_t);

typedef struct{ ... } i2cmessage_t;
and replace that with:

struct i2cmessage_s { ... };

Or use:

struct i2cmessage_s;
typedef void (*i2c_callback) (struct i2cmessage_s);
typedef struct i2cmessage_s { ... } i2cmessage_t;

--
Hallvard
Aug 3 '06 #2
>I want to use a pointer to a methode that has a struct (i2cmessage_t)
>as a parameter. This struct should have the pointer to the previously
defined methode as one of its members.
struct i2cmessage_s;
typedef void (*i2c_callback) (struct i2cmessage_s); typedef struct
i2cmessage_s { ... } i2cmessage_t;
Thanks,
I got it working nicely.

grz,
Onno
Aug 3 '06 #3
In article <pa****************************@gorgoz.org>
Onno <de*******@gorgoz.orgwrote:
>I want to use a pointer to a method that has a struct (i2cmessage_t) as a
parameter. This struct should have the pointer to the previously defined
methode as one of its members.
(C does not have anything formally called "methods", but your intent
is clear enough.)
>typedef void (*i2c_callback) (i2cmessage_t);

typedef struct{
slaveAddress_t slaveAddress;
uint8_t * sendBuffer;
uint8_t sendBufferLength;
uint8_t * receiveBuffer;
uint8_t receiveBufferLength;
i2c_callback callbackFunction;
} i2cmessage_t;
See <http://web.torek.net/torek/c/types2.html>, in particular the
section on self- and mutually-referential types.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Aug 3 '06 #4
See <http://web.torek.net/torek/c/types2.html>, in particular the
section on self- and mutually-referential types.
Thanks Chris, I understand the situation now.
I bookmarked the URL for future reference.

grz,
Onno
Aug 5 '06 #5

Onno wrote:
I want to use a pointer to a methode that has a struct (i2cmessage_t)
as a parameter. This struct should have the pointer to the previously
defined methode as one of its members.
struct i2cmessage_s;
typedef void (*i2c_callback) (struct i2cmessage_s); typedef struct
i2cmessage_s { ... } i2cmessage_t;

Thanks,
I got it working nicely.
You might note the following: (taken from the info
page for libc):

* Names that end with `_t' are reserved for additional type names.

--
Bill Pursell

Aug 5 '06 #6
"Bill Pursell" <bi**********@gmail.comwrites:
Onno wrote:
>I want to use a pointer to a methode that has a struct (i2cmessage_t)
as a parameter. This struct should have the pointer to the previously
defined methode as one of its members.
struct i2cmessage_s;
typedef void (*i2c_callback) (struct i2cmessage_s); typedef struct
i2cmessage_s { ... } i2cmessage_t;

Thanks,
I got it working nicely.

You might note the following: (taken from the info
page for libc):

* Names that end with `_t' are reserved for additional type names.
The C standard doesn't reserve names ending in "_t". Is that a POSIX
thing?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 5 '06 #7
Keith Thompson said:
"Bill Pursell" <bi**********@gmail.comwrites:
>>
You might note the following: (taken from the info
page for libc):

* Names that end with `_t' are reserved for additional type names.

The C standard doesn't reserve names ending in "_t". Is that a POSIX
thing?
Yes. It's useful knowledge, even though - strictly speaking - it's nothing
to do with C. One would not wish to tread on POSIX's namespace toes by
mistake. (To do so deliberately would be another matter; if one chooses to
do so, presumably one has a good reason.)

--
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)
Aug 5 '06 #8

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

Similar topics

3
by: Thomas Mailund | last post by:
Hi group. I have a problem with some C extensions I am working with and hope that some of you can help. Basically, I am wrapping a a tree structure from C where I have python methods for...
7
by: Brian Sabolik | last post by:
I'm not sure if I've broken any Object Oriented rules or not, but ... I have projects in 2 different solutions that need to use each other's methods. Therefore I may have an "update" method in...
9
by: John Doe | last post by:
Hi all, Regarding those cyclic dependencies of classes (like cases in which class A refers to class B and class B to class A): can they ALL be resolved by forward defining classes, and by...
0
by: Scott Ribe | last post by:
I've got a problem which I think may be a bug in Postgres, but I wonder if I'm missing something. Two tables, A & B have foreign key relations to each other. A 3rd table C, inherits from A. A...
2
by: Matthias Kramm | last post by:
Hi All, I'm having a little bit of trouble using the "imp" module to dynamically import modules. It seems that somehow cyclic references of modules don't work. I'm unable to get the following...
3
by: Pohihihi | last post by:
This is a report from VSS newsgroup in hope of getting some more suggestions. Thanks, Po ------------------------------------------- I guess I am not getting the whole picture here. How does...
3
by: fc2004 | last post by:
Hi, Is there any tools that could report where cyclic header dependency happens? this would be useful when working with a large project where tens or hundreds of headers files may form complex...
10
by: toton | last post by:
Hi I have a class called Session, which stores a vector of Page, like vector<PageAlso each Page need's to know the Session to which it is attached. Thus I have, (the classes has many other...
1
by: Joe Peterson | last post by:
I've been doing a lot of searching on the topic of one of Python's more disturbing issues (at least to me): the fact that if a __del__ finalizer is defined and a cyclic (circular) reference is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.