Jump to content

Typedef Struct With Function Pointers


Recommended Posts

I have this typedef struct, keep getiting error: missing right brace.

 

typedef struct

{

unsigned char (*init_if)(void *instance);

unsigned char (*read_message)(void *instance1);

unsigned char (*write_message)(void *instance2);

} serial_if_driver_t;

 

I had a quick look around the forums, it seems that as far back as 2007 this was flagged as an issue, is there a solution??

 

Thanks, Alan

Link to post
Share on other sites
I have this typedef struct, keep getiting error: missing right brace.

 

typedef struct

{

unsigned char (*init_if)(void *instance);

unsigned char (*read_message)(void *instance1);

unsigned char (*write_message)(void *instance2);

} serial_if_driver_t;

 

I had a quick look around the forums, it seems that as far back as 2007 this was flagged as an issue, is there a solution??

 

Thanks, Alan

 

Come on Sourceboost, I need soome help on this one!!

Link to post
Share on other sites

We are looking into this right now. Compiler does not support struct members of type function pointers. Hopefully we'll add this feature by the next release. However even when this feature is available it will be very expensive in terms of code/data space (because of PIC architecture). If your design allows you should use function pointers as little as possible (if not at all).

 

Regards,

Pavel

Link to post
Share on other sites
We are looking into this right now. Compiler does not support struct members of type function pointers. Hopefully we'll add this feature by the next release. However even when this feature is available it will be very expensive in terms of code/data space (because of PIC architecture). If your design allows you should use function pointers as little as possible (if not at all).

 

Regards,

Pavel

 

Thanks for the reply, expensive or not it stands to reason for any compiler that is ANSI-C should be able to do function pointers in struct's, looking back this has been flagged years ago, and still no support?? Bit disapointed to say the least after splashing £100 for the compilier, actually this is the second time that I have purchased it.

 

Anyhow is there a different way to get function pointers into structs??

 

Also could you please comment on this?

 

typedef struct serial_if_driver_t{

unsigned char init_if();

unsigned char read_message();

unsigned char write_message();

} serial_if_driver_t;

 

error: ',' expected ??

 

Cheers, Alan.

Link to post
Share on other sites
Thanks for the reply, expensive or not it stands to reason for any compiler that is ANSI-C should be able to do function pointers in struct's, looking back this has been

 

Yes it should. Nobody argues about this. However PIC is not a good platform for a design that uses many function pointers. It's better either to review program architecture or move to different CPU.

 

flagged years ago, and still no support?? Bit disapointed to say the least after splashing £100 for the compilier, actually this is the second time that I have purchased it.

 

That's why we offer free compiler on our web site. Everybody can download and try it before purchasing.

 

Anyhow is there a different way to get function pointers into structs??

 

No

 

Also could you please comment on this?

 

typedef struct serial_if_driver_t{

unsigned char init_if();

unsigned char read_message();

unsigned char write_message();

} serial_if_driver_t;

 

error: ',' expected ??

 

This is C++ syntax and BoostC won't compile it. You need BoostC++ to compile such code.

 

Regards,

Pavel

Link to post
Share on other sites
Thanks for the reply, expensive or not it stands to reason for any compiler that is ANSI-C should be able to do function pointers in struct's, looking back this has been

 

Yes it should. Nobody argues about this. However PIC is not a good platform for a design that uses many function pointers. It's better either to review program architecture or move to different CPU.

 

flagged years ago, and still no support?? Bit disapointed to say the least after splashing £100 for the compilier, actually this is the second time that I have purchased it.

 

That's why we offer free compiler on our web site. Everybody can download and try it before purchasing.

 

Anyhow is there a different way to get function pointers into structs??

 

No

 

Also could you please comment on this?

 

typedef struct serial_if_driver_t{

unsigned char init_if();

unsigned char read_message();

unsigned char write_message();

} serial_if_driver_t;

 

error: ',' expected ??

 

This is C++ syntax and BoostC won't compile it. You need BoostC++ to compile such code.

 

Regards,

Pavel

 

Ok, thanks for the info.

Link to post
Share on other sites
Thanks for the reply, expensive or not it stands to reason for any compiler that is ANSI-C should be able to do function pointers in struct's, looking back this has been

 

Yes it should. Nobody argues about this. However PIC is not a good platform for a design that uses many function pointers. It's better either to review program architecture or move to different CPU.

 

flagged years ago, and still no support?? Bit disapointed to say the least after splashing £100 for the compilier, actually this is the second time that I have purchased it.

 

That's why we offer free compiler on our web site. Everybody can download and try it before purchasing.

 

Anyhow is there a different way to get function pointers into structs??

 

No

 

Also could you please comment on this?

 

typedef struct serial_if_driver_t{

unsigned char init_if();

unsigned char read_message();

unsigned char write_message();

} serial_if_driver_t;

 

error: ',' expected ??

 

This is C++ syntax and BoostC won't compile it. You need BoostC++ to compile such code.

 

Regards,

Pavel

 

Hello Pavel,

 

Even more basic then above, I cannot get this to compile?? Is there something that I am missing with structs and SB?

 

struct {

unsigned char name[30];

unsigned char street[40];

unsigned char city[20];

unsigned char state[3];

unsigned int zip;

} addr_info;

 

addr_info.zip=123;

 

Regards, Alan

Link to post
Share on other sites

Alan,

 

Your assignment has to be inside a pair of braces. Either the structure or a function/procedure.

 

Cheers

 

Reynard

 

Well! Maybe not structures then ;)

Edited by Reynard
Link to post
Share on other sites
Thanks for the reply, expensive or not it stands to reason for any compiler that is ANSI-C should be able to do function pointers in struct's, looking back this has been

 

Yes it should. Nobody argues about this. However PIC is not a good platform for a design that uses many function pointers. It's better either to review program architecture or move to different CPU.

 

flagged years ago, and still no support?? Bit disapointed to say the least after splashing £100 for the compilier, actually this is the second time that I have purchased it.

 

That's why we offer free compiler on our web site. Everybody can download and try it before purchasing.

 

Anyhow is there a different way to get function pointers into structs??

 

No

 

Also could you please comment on this?

 

typedef struct serial_if_driver_t{

unsigned char init_if();

unsigned char read_message();

unsigned char write_message();

} serial_if_driver_t;

 

error: ',' expected ??

 

This is C++ syntax and BoostC won't compile it. You need BoostC++ to compile such code.

 

Regards,

Pavel

 

Hello Pavel,

 

Thanks for the advice "It's better either to review program architecture or move to different CPU."

 

Heres some advice also how about removing ANSI-C compatible from page 9 of your datasheet/manual.

 

Regards, Alan

Link to post
Share on other sites
...Even more basic then above, I cannot get this to compile?? Is there something that I am missing with structs and SB?

 

struct {

unsigned char name[30];

unsigned char street[40];

unsigned char city[20];

unsigned char state[3];

unsigned int zip;

} addr_info;

 

addr_info.zip=123;

 

Regards, Alan

 

 

This code does not compile because it's not valid C syntax. Insert your code inside a function and it will compile just fine.

 

Like this:

#include <system.h>

void main()
{
struct {
unsigned char name[30];
unsigned char street[40];
unsigned char city[20];
unsigned char state[3];
unsigned int zip;
} addr_info;

addr_info.zip=123;
}

 

Or like this:

#include <system.h>

struct {
unsigned char name[30];
unsigned char street[40];
unsigned char city[20];
unsigned char state[3];
unsigned int zip;
} addr_info;

void main()
{
addr_info.zip=123;
}

 

Regards,

Pavel

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...