473,326 Members | 2,127 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,326 software developers and data experts.

Order of definitions

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
3 1190

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

"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
[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 (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.
Nov 15 '05 #4

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

Similar topics

14
by: Joerg Schuster | last post by:
Hello, according to http://mail.python.org/pipermail/tutor/2001-July/007246.html the order of function definitions does matter in python. Does anyone know a trick to avoid this? Is there a...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
39
by: Nicolas Fleury | last post by:
In the following example: class MyMetaclass(type): pass class MyBaseType(object): __metaclass__ = MyMetaclass class MyType(MyBaseType): x = 4 y = 5 z = 6 Is there any way to modify...
0
by: Derrick | last post by:
I've created a suite of custom controls/components. I have 3 assemblies, as follows: - Definitions.dll: This contains classes and interfaces that are common to the other 2 assemblies. There...
4
by: dtwalter | last post by:
Is it possible to ORDER BY a SubSelect? I don't see why it wouldn't be, but I'm having some trouble. Hopefully it's just a simple error in syntax and somebody can tell me. Here's what I'm trying...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
6
by: Együd Csaba | last post by:
Hi All, I'd like to dump out my database using plain text format. Everything is ok, but the bytea filds. Restoring the dump file (using <<psql -f LO_TRY_INSERT_BYTEA.sql tmp7>>) it sends an...
2
by: elein | last post by:
Yes, I vacuumed. Reproduced on both 7.3.2 and 7.5. Brain dead java beans want order by clauses in views that they use. my view is: select .... from bigtable b left join lookuptable l order...
4
by: Frederick Gotham | last post by:
What do you think of the following code for setting and retrieving the value of bytes in an unsigned integer? The least significant bit has index 0, then the next least significant bit has index 1,...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.