Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpSyntax › #define and Wiring IDE formtatting error

Page Index Toggle Pages: 1
#define and Wiring IDE formtatting error (Read 3562 times)
10/14/10 at 13:59:37

roypardi   Offline
Junior Member
I Love YaBB 2!
Boston USA

Posts: 57
**
 
Hi - I'm using some code from the RepRap project. It uses some macro #defines that break after I use the IDE formatting.

This is the "before" formatting:
Code (C++):
#define PARSE_INT(ch, instr, str, str_size, len, val, seen, flag) \
    case ch: \
        len = scan_int(str, &val, &seen, flag); \
        break; 



This is the result "after" formatting - note how the slashes have moved
Code (C++):
#define PARSE_INT(ch, instr, str, str_size, len, val, seen, flag) \
    case ch:
\
        len = scan_int(str, &val, &seen, flag);
\
        break; 



After formatting the code won't compile so it gets to be a pain. I don't really understand the #defines enough to rewrite them as functions (tried). Is there something else I can do so that I can format my code without breaking it?

--Thanks! Roy (any explanation of macro #defines also welcome)
 
IP Logged
 
Reply #1 - 10/14/10 at 15:05:58

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
hi Roy, yes it is a problem due to spaces, after the character '\' there can't be any comments or spaces it has to be the last character. The macros has to be one line, if it is too long the character '\' can be used. The Autoformat tool is breaking this rule. This article talks about it: http://docs.hp.com/en/92501-90029/ch02s03.html also check the Wiring source code for WConstants.h there are some examples there used by the language: http://wiring.uniandes.edu.co/source/trunk/wiring/core/WConstants.h?revision=828&view=markup
One thing could be to put your defines inside an include file and call it from the sketch #include "myinclude.h" and put the file myinclude.h inside your sketch folder.
There is an example of a function like macro inside http://wiring.uniandes.edu.co/source/trunk/wiring/core/WProgram.h?revision=828&view=markup check the definition of digitalWrite in there it might help you. Let me know. I'll look into the Autoformat tool to see how we can fix this for future versions.
 
IP Logged
 
Reply #2 - 10/15/10 at 13:37:52

roypardi   Offline
Junior Member
I Love YaBB 2!
Boston USA

Posts: 57
**
 
hi barragan - thanks for the prompt reply!

These macros are short so I tried rewriting them all on one line and they compile (haven't tried to run the code off the board yet).

Code (C++):
#define PARSE_INT(ch, instr, str, str_size, len, val, seen, flag) case ch: len = scan_int(str, &val, &seen, flag);  break; 



Not ideal but in this case easy enough to read in the IDE window.

Thanks again for Wiring. I have two first gen boards that I have used for countless projects. I seem to have blown the ability to power them through USB (after changing the jumper, etc) but other than that they have been really solid.

--Roy
 
IP Logged
 
Reply #3 - 10/15/10 at 21:37:15

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
hi Roy, great, regarding the power it might be the fuse in the old boards you can bypass it with a blob of soldering, it should be fine.
 
IP Logged
 
Page Index Toggle Pages: 1