Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Syntax >> #define and Wiring IDE formtatting error
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1287064777

Message started by roypardi on 10/14/10 at 13:59:37

Title: #define and Wiring IDE formtatting error
Post by roypardi on 10/14/10 at 13:59:37
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;[/code]

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;[/code]

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)

Title: Re: #define and Wiring IDE formtatting error
Post by barragan on 10/14/10 at 15:05:58
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.

Title: Re: #define and Wiring IDE formtatting error
Post by roypardi on 10/15/10 at 13:37:52
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;[/code]

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

Title: Re: #define and Wiring IDE formtatting error
Post by barragan on 10/15/10 at 21:37:15
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.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.