Pinguino Forum
Pinguino 12 - min macro in sdcc - Printable Version

+- Pinguino Forum (http://forum.pinguino.cc)
+-- Forum: Software (http://forum.pinguino.cc/forumdisplay.php?fid=7)
+--- Forum: Syntax & Programs (http://forum.pinguino.cc/forumdisplay.php?fid=19)
+--- Thread: Pinguino 12 - min macro in sdcc (/showthread.php?tid=4855)



Pinguino 12 - min macro in sdcc - DickBr - 29-06-2016

When getting a compiler  error on min(var, var2), which compiled in Pinguino 11, I found that in macro.h the min and max macro is commented out.


Code:
    //#ifndef __XC8__
        //#define min(a,b)            ((a)<(b)?(a):(b))
        //#define min(x, y)           (y ^ ((x ^ y) & -(x < y)))
        //#define max(a,b)            ((a)>(b)?(a):(b))
        //#define max(x, y)           (x ^ ((x ^ y) & -(x < y)))
    //#endif

After changing this to


Code:
    //#ifndef __XC8__
        #define min(a,b)            ((a)<(b)?(a):(b))
        //#define min(x, y)           (y ^ ((x ^ y) & -(x < y)))
        #define max(a,b)            ((a)>(b)?(a):(b))
        //#define max(x, y)           (x ^ ((x ^ y) & -(x < y)))
    //#endif

like it is in the macro.h of version 11 the sketch compiles without errors.

Is this a regression or did I mis something obvious?

btw, I like the Pinguino IDE 12 very much.

Thanks for all the good work, Dick


RE: Pinguino 12 - min macro in sdcc - gtcbreizh - 30-06-2016

Hello Dick,
There is obviously a mistake. You are right by coming back to the uncommented definitions version 11.
André


RE: Pinguino 12 - min macro in sdcc - DickBr - 30-06-2016

Oops....  and of course the double slashes have to be removed before the #ifndef __XC8__ and #endif
to prevent errors when compiling with the xc8 compiler. [Image: smile.gif]


Code:
    #ifndef __XC8__
       #define min(a,b)            ((a)<(b)?(a):(b))
       //#define min(x, y)           (y ^ ((x ^ y) & -(x < y)))
       #define max(a,b)            ((a)>(b)?(a):(b))
       //#define max(x, y)           (x ^ ((x ^ y) & -(x < y)))
   #endif



RE: Pinguino 12 - min macro in sdcc - gtcbreizh - 30-06-2016

Hello Dick,
I don't agree !
You have to let // before #ifndef  __XC8__ and #endif because the definitions for min and max are correct for SDCC and XC8

But simply the better thing to do is to delete the //#ifndef ... and //#endif
André


RE: Pinguino 12 - min macro in sdcc - DickBr - 03-07-2016

Hello Andre,

If the min and max macro's are enabled in a XC8 compilation the compiler will give a redefine warning.
The XC8 compiler has min and max macro's defines in stdlib.h and they do the same as min/max in Pinguino's macro.h.
So it's not a problem to keep the #ifndef __XC8__ commented out but it will give a redefine warning which may confuse people.
I hope you can agree with this.

Dick.


RE: Pinguino 12 - min macro in sdcc - gtcbreizh - 03-07-2016

Hello Dick,
Sorry ! I did not know with regard to XC8 the min and max functions were already defined in stdlib.h.
Many thanks for this information. So I modify my macro.h.
André