View previous topic :: View next topic |
Author |
Message |
bartholomew
Joined: 19 Sep 2003 Posts: 3
|
function pointers are not ready for prime time |
Posted: Fri Sep 19, 2003 1:15 am |
|
|
So I just wasted most of a day trying to get function pointers to work in CCS. My experience is that the implementation is incredibly buggy.
(I'm using 3.173 -- haven't updated to 3.178 because the release notes don't suggest that these poblems have been fixed, and last time I updated on a whim I lost another day's work.)
Here's an example of what I mean by buggy:
The following compiles fine:
Code: |
#include <18f452.h>
typedef int1 bool;
typedef bool (*FuncFoo) ();
void main() {
}
|
The following code (functionally identical) fails to compile with error:
Error[38] ... This type can not be qualified with this qualifier
Code: |
#include <18f452.h>
typedef int1 (*FuncFoo) ();
void main() {
}
|
Does this sort of thing drive anyone else mad?
-bart |
|
|
bartholomew
Joined: 19 Sep 2003 Posts: 3
|
another example... |
Posted: Fri Sep 19, 2003 1:25 am |
|
|
Here's another example of function pointer bugginess.
The following compiles fine:
Code: | #include <18f452.h>
typedef int (*FuncFoo) ();
int foo() {
// do nothing
}
void main() {
FuncFoo someFunction;
someFunction = foo;
(*someFunction)();
} |
However if I comment out the last line (*someFunction)(); I
get:
Error[44] ... Internal Error - Contact CCS LABEL SCR = 356
and if I leave it commented out but make someFunction global, I get:
Error[44] ... Internal Error - Contact CCS LABEL SCR = 354
Anyway, generally CCS is happy to assign foo to someFunction, but what if the assignee is part of a struct?
Code: | #include <18f452.h>
typedef int (*FuncFoo) ();
int foo() {
// do nothing
}
struct {
FuncFoo someFunction;
} gFuncStruct;
void main() {
gFuncStruct.someFunction = foo;
} |
In this case, CCS errors out with
Error[117] ... Improper use of a function identifier
What does this mean?
-bart |
|
|
bartholomew
Joined: 19 Sep 2003 Posts: 3
|
third example of function pointer bugginess... |
Posted: Fri Sep 19, 2003 1:33 am |
|
|
Here's my last example for the day of why CCS's function pointer implementation is not ready for prime time.
The following code compiles fine:
Code: | #include <18f452.h>
typedef void (*FuncNothing) (char c);
typedef char (*FuncReceive) ();
FuncNothing sFuncNothing;
void nothing(char c) {
// do nothing
}
void neverCalled() {
sFuncNothing = nothing;
}
void main() {
} |
Yes I know that it is pretty pointless code, but it is analogous to a heap of code I just wrote. Anyway, suppose I swap the order of the two typedefs, so the code is as follows:
Code: | typedef char (*FuncReceive) ();
typedef void (*FuncNothing) (char c); |
When I do the above, I get the error:
Error[118] ... Invalid type conversion
Can you imagine how frustrating it is to track down bugs when the order of typedefs matters to CCS? Has anyone put together a list of what works and what doesn't with function pointers?
Downloading MPLABŪ C18 free demo now to see if Microchip do it any better...
-bart |
|
|
Darren Rook
Joined: 06 Sep 2003 Posts: 287 Location: Milwaukee, WI
|
|
Posted: Fri Sep 19, 2003 7:52 am |
|
|
I thought pointers to functions were beta. In fact, I don't think they've even been documented yet. |
|
|
Guest
|
|
Posted: Thu Jan 15, 2004 10:15 am |
|
|
after ver 3.160 function pointers are supported |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 15, 2004 10:47 am |
|
|
You're talking about this comment:
"3.160 Pointers to functions are now supported"
on the versions page, http://www.ccsinfo.com/versions.shtml
For your information, just because CCS announces something
there, it doesn't mean that it's fully tested. It means that
they've newly added it as a feature. It may, and often does,
have bugs for a while. |
|
|
Darren Rook
Joined: 06 Sep 2003 Posts: 287 Location: Milwaukee, WI
|
|
Posted: Thu Jan 15, 2004 12:03 pm |
|
|
Yes, beta.
Support added, not documented. Also "supported added" in the version update page doesn't mean full support added.
Progress has to start somewhere.
You've put a lot of work and thought into this, please e-mail everything to CCS - including source code, .lst file, and description of each problem. |
|
|
h Guest
|
|
Posted: Thu Jan 22, 2004 1:42 pm |
|
|
so, when do you think function pointers will be ready for everyday use? |
|
|
|