By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,952 Members | 1,424 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,952 IT Pros & Developers. It's quick & easy.

Order of definitions

P: n/a
Hello group!

I have a (basic, I guess) question about the order of my definitions...

I have the following (a structure to wrap the data of a thread):

/* Thread data */
typedef struct tTkThread {
/* <snip>...</snip> */

void *pRunFunc;
} TkThread;

/* Thread procedure */
typedef void (*TkThreadProcedure)(TkThread *pThis);
My question is: How do I change the type of pRunFunc from void* to
TkThreadProcedure?

If I do my definitions in the order shown above, the compiler will complain
about not knowing the TkThreadProcedure function pointer type.

If I switch the order of the function pointer typedef and the structure def,
the compiler will complain that it does not know the TkThread structure.

Thanks in advance!

-Mogens
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

Mogens Heller Jensen wrote:
Hello group!

I have a (basic, I guess) question about the order of my definitions...

I have the following (a structure to wrap the data of a thread):

/* Thread data */
typedef struct tTkThread {
/* <snip>...</snip> */

void *pRunFunc;
} TkThread;

/* Thread procedure */
typedef void (*TkThreadProcedure)(TkThread *pThis);
My question is: How do I change the type of pRunFunc from void* to
TkThreadProcedure?

If I do my definitions in the order shown above, the compiler will complain
about not knowing the TkThreadProcedure function pointer type.

If I switch the order of the function pointer typedef and the structure def,
the compiler will complain that it does not know the TkThread structure.

Thanks in advance!

-Mogens


struct tTkThread;
typedef struct tTkThread TkThread;

typedef void (*TkThreadProcedure)(TkThread *pThis);

struct tTkThread {
...
TkThreadProcedure pRunFunc;
};

Nov 15 '05 #2

P: n/a

"John Bode" <jo*******@my-deja.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

Mogens Heller Jensen wrote:
Hello group!

I have a (basic, I guess) question about the order of my definitions...

I have the following (a structure to wrap the data of a thread):

/* Thread data */
typedef struct tTkThread {
/* <snip>...</snip> */

void *pRunFunc;
} TkThread;

/* Thread procedure */
typedef void (*TkThreadProcedure)(TkThread *pThis);
My question is: How do I change the type of pRunFunc from void* to
TkThreadProcedure?

If I do my definitions in the order shown above, the compiler will
complain
about not knowing the TkThreadProcedure function pointer type.

If I switch the order of the function pointer typedef and the structure
def,
the compiler will complain that it does not know the TkThread structure.

Thanks in advance!

-Mogens


struct tTkThread;
typedef struct tTkThread TkThread;

typedef void (*TkThreadProcedure)(TkThread *pThis);

struct tTkThread {
...
TkThreadProcedure pRunFunc;
};


Oh yeah, I tried something like that - but I see now that I forgot the
"struct" part of the typedef (I'm more used to C++ you see...).

I tried this in MSVC7 and it works perfectly. But it does not work in my
case - it seems the compiler is stupid/not fully compliant with the
standard. I am using the Codevision C compiler for the Atmel Atmega16
microcontroller.

Thanks for the input!

-Mogens
Nov 15 '05 #3

P: n/a
[In the original, Mogens Heller Jensen shows code that does not compile
because the typedef-name occurs after the point where it is needed.]
"John Bode" <jo*******@my-deja.com> wrote in message
news:11**********************@z14g2000cwz.googleg roups.com...
struct tTkThread;
typedef struct tTkThread TkThread;

typedef void (*TkThreadProcedure)(TkThread *pThis);

struct tTkThread {
...
TkThreadProcedure pRunFunc;
};

In article <43***********************@nntp02.dk.telia.net>
Mogens Heller Jensen <mo****@mookid.dk> wrote:I tried this in MSVC7 and it works perfectly.
It should; it is valid Standard C (both the old 1989 ANSI/ISO
standard, and the new 1999 ISO standard).
But it does not work in my case - it seems the compiler is stupid/not
fully compliant with the standard. I am using the Codevision C compiler
for the Atmel Atmega16 microcontroller.


You might try another newsgroup, as this one (comp.lang.c) is all
about Standard C, so we can only tell you that this compiler appears
to be broken (although to be sure of that, we would have to have a
complete sample that fails to compile).

On the other hand, you might also try removing all the "typedef"s
entirely. Remember that in C, typedef does not define types. It
just gives you a new name for an existing type. The above
can be rewritten as:

/* think of the keyword "struct" as meaning "type"; your type is
named TkThread */
struct TkThread {
...
void (*pRunFunc)(struct TkThread *pThis);
};

All you have to do is write out the "type" keyword each time,
spelling it "wrong": "STRange spelling for User-defined abstraCt
Type", or "struct".
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.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.
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.