Shop OBEX P1 Docs P2 Docs Learn Events
#define — Parallax Forums

#define

AGCBAGCB Posts: 327
edited 2014-09-03 17:22 in General Discussion
I was looking at an object the other day to learn from the coding of the writer and came across this
#ifdefine   xxxx
...code...
endif

I remember this from when I used to program PICs but have never seen it in a propeller program. I looked in the propeller manual and could not find anything. Upon trying to compile the object, it gave an error. It seemed to be a regular SPIN program

Would someone enlighten me as to why, how what etc.?

Thanks.
Aaron

Comments

  • Heater.Heater. Posts: 21,230
    edited 2014-09-03 13:13
    What language are you compiling there?

    Spin from Parallax, as in the Propeller Tool, does not have such a construct.

    Spin compilers created by others, like BST, have added features to the language. Like #define for example.

    "#ifdefine" comes from the archaic C language. (Where is was "ifdef...")

    Basically the idea is that you may want to include or exclude different bits of code at compile time according to some definitions given to the compiler when you run it. Those definitions can also be included in the code "#define useSomeFeature 1" for example.

    Hmm...if you are posting that code correctly you cannot be trying to compile C which has "#ifdef" not "#ifdefine".

    It was always speculated that adding features to Spin would cause confusion. Many years later here we are:)

    What is the Spin object you are building?
  • David BetzDavid Betz Posts: 14,516
    edited 2014-09-03 13:27
    Heater. wrote: »
    It was always speculated that adding features to Spin would cause confusion. Many years later here we are:)
    I sometimes find the unextended Spin confusing. I had to look up many of the operators that JonnyMac used in his DEFCON badge when I translated the code to C++. :-)
  • Heater.Heater. Posts: 21,230
    edited 2014-09-03 13:51
    David,

    Well, yeah. Spin is not C. It's a different language.

    I know your pain. Spin is not C and it confuses old C hands. It especially trips you up when swapping between Spin and C in a hurry.

    Of course no body knows what the operators in C++ mean, they are overridable.

    And good luck with Javascript :)
  • AGCBAGCB Posts: 327
    edited 2014-09-03 15:50
    It's definitely a spin program (I think). Here's the CON block from the beginning of a top object.
    {{
    ┌──────────────────────────────────────────┐
    │ LMM I2C Test Driver 1.1                  │
    │ Author: Tim Moore                        │
    │ Copyright (c) June 2010 Tim Moore        │
    │ See end of file for terms of use.        │
    └──────────────────────────────────────────┘
    
     Supports writing I2C device driver objects that use inline PASM
    
    }}
    CON
    '  _clkmode = xtal1 + pll16x
    '  _xinfreq = 5_000_000
      _clkmode        =             xtal1 + pll8x
      _xinfreq        =             10_000_000
    
    #define LMM                     'enable lmm
    #define QUICKATAN2              'enable faster atan2
    #define I2CDEBUG                'display debug messages when i2c fails
    

    And this is an OBJ block from a child object
    OBJ
      uarts       : "pcFullDuplexSerial4FC"                 '1 COG for 4 serial ports
    
      i2cObject   : "basic_i2c_driver"                      '0 Cog
      umath :       "umath"                                 '0 Cog
    
    #ifdef LMM
      lmm         : "SpinLMM"
    
      i2clmm      : "i2clmm"                                '0 Cog
    #endif
    

    I just wondered if I was missing something as I've not seen this in a spin program before although the same thing is used in the Microchip PIC MPLAB IDE.

    Thanks
    Aaron
  • GenetixGenetix Posts: 1,754
    edited 2014-09-03 16:50
    Those look like compiler directives.
  • Cluso99Cluso99 Posts: 18,069
    edited 2014-09-03 17:22
    Its a program written for compiling with bst or homespun. Both are compilers written but AFAIK are now unsupported.
    But, don't despair. Both work nicely. Catalina C used homespun up until the latest versions. I use bst to compile ZiCog.
Sign In or Register to comment.