Need Help with PropGCC (Function types & prototypes) [SOLVED]
JonnyMac
Posts: 9,102
I thought it would be a fun diversion to port my TM1637 driver to C -- I am now regretting that, but angry enough not to quit.
I keep getting silly warnings like this:
...but when I add function prototypes, things get even worse:
Why? Why is PropGCC giving my functions an implicit type when I am EXPLICITLY declaring them as void or uint8_t?
I keep getting silly warnings like this:
TM1637_Demo.c:45:3: warning: implicit declaration of function 'tm1637_begin' [-Wimplicit-function-declaration]
TM1637_Demo.c:46:3: warning: implicit declaration of function 'tm1637_write' [-Wimplicit-function-declaration]
TM1637_Demo.c:47:3: warning: implicit declaration of function 'tm1637_end' [-Wimplicit-function-declaration]
...but when I add function prototypes, things get even worse:
TM1637_Demo.c:45:3: warning: implicit declaration of function 'tm1637_begin' [-Wimplicit-function-declaration]
TM1637_Demo.c:46:3: warning: implicit declaration of function 'tm1637_write' [-Wimplicit-function-declaration]
TM1637_Demo.c:47:3: warning: implicit declaration of function 'tm1637_end' [-Wimplicit-function-declaration]
Why? Why is PropGCC giving my functions an implicit type when I am EXPLICITLY declaring them as void or uint8_t?
Comments
Here is the corrected code; this compiles as expected.
The two warning blocks seems the same to me (wrong copy/paste ?), anyway, C see declarations from top to down in the source, whenever you call a function that is defined after it assumes a standard declaration, then it throws a warning if the actual definition is different.
In your code, tm1637_begin and tm1637_end are not present (this will give you an error in the linker phase), tm1637_write is used in the fill function but defined later after the start function.
If you uncomment the function declarations at top, you should be fine (well, after adding a semicolon after the fill prototype).
Or reorder the functions so they call only functions defined before them, if possible.
Sharing the pain with a wry smile!
To fix up the compile errors, try replacing your currently commented out block of function declarations with this code:
You were missing a couple functions, and also the _fill declaration was missing a semicolon at the end of the line.
One other thing... Do those if/else constructs require curly braces ?
Oh- and also the For loops ? I'm not sure about that.
These code snippets seem to compile OK from Jon's example in SimpleIDE.... at least there's no reported errors.
and
However, are curly braces required to ensure the code operates as expected ? What are the rules about that ?
It looks like "braces not required when code follows on 1 line only".... Is that a correct assumption ?
They look great for Spin (indented) though
That makes it very clear; Thanks @Wuerfel_21
dgately
My syntax is correct. I'm not a master of C, but I know it well enough to get syntax right (and I keep a few books handy to double-check when I have questions).
The compiler setting (-std=C99) was already in place.
I apologize... I may have caused bit of confusion by renaming a couple functions after posting the original warnings. These are the warnings with the code above (function prototypes commented out).
These are the warnings when I remove the comment block from the function prototypes.
This is a lot better in recent GCC versions (due to GCC's monopoly on being a decent C/C++ compiler being disturbed by clang/LLVM), but alas, no one maintained the Prop version.
It compiles now.
I understand. I am -- at the moment -- simply translating my Spin library code to C. Once everything is working I will move the move things to the .h and .c files as one would expect with a proper library.
To those, especially @Wuerfel_21, who assisted, thank you.
A lot of the translation from Spin to C can be automated via spin2cpp, if you'd like to save time.
I could, but it would deny me the opportunity to learn as I go. For me this is about learning, not about saving time.
I have several text files where I keep notes about language conversions so I don't have to keep relearning what to do.
I don't know what system you use but it's a good idea to keep notes on what to do or what to be careful of.
As for style, I prefer to indent braces under the function or statement that they go with.