What is the syntax for a #define for several lines of code?

This is a discussion on What is the syntax for a #define for several lines of code? within the C Programming forums, part of the General Programming Boards category; What is the syntax for a #define for several lines of code? For example: #define SEND <syntax> setPort();clearDisplay() <end syntax> ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    1

    What is the syntax for a #define for several lines of code?

    What is the syntax for a #define for several lines of code? For example:


    #define SEND <syntax> setPort();clearDisplay() <end syntax>

    Thought it'd b a simple

    #define SEND {setPort();clearDisplay()}

    or

    #define SEND (setPort();clearDisplay())

    but no, won't work... By the way I'm using the SDCC compiler for 8051 micro controllers.

    seen an example of a weird syntax dividing lines with the '/' sign, but can't seem to make that work either

    thanx for your help

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Code:
    #define SEND {setPort();clearDisplay();}

  3. #3
    wtf
    Guest
    #define x printf("heh"); \
    printf("wtf lol\n");

  4. #4
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Originally posted by wtf
    #define x printf("heh"); \
    printf("wtf lol\n");
    Yeh, thats even better. But it does lead to messy code. If youre going to do lots of things in a #define you might as well just make it a function.

  5. #5
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    I was wondering if this could properly be called a function macro?
    Code:
    #define SEND {setPort();clearDisplay();}
    Also, this:
    originally posted by Brian
    Yeh, thats even better. But it does lead to messy code. If youre going to do lots of things in a #define you might as well just make it a function.
    An exception would be if the #define made things speedier?

  6. #6
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    Originally posted by kermit

    An exception would be if the #define made things speedier?
    with modern compilers, operating systems, and processors function calls take a negligible amount of time ( in most cases ).

    When designing code you should always design for readability above all else, and then when the project is complete analyze the system and if you find overly time-consuming areas, optimize those.

  7. #7
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    I'd have thought that speed would have been the priority over readability when programming a PIC
    "Assumptions are the mother of all **** ups!"

  8. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Readability does not necessarily have influence on the speed. One can write unreadable code which is very slow.

    What about inline functions? Does your compiler support this? Inline functions are very readable, but they are no real functions. Your compiler will try to make calls to inline functions as fast as possible.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. Error check problem again
    By rtransfi in forum C Programming
    Replies: 6
    Last Post: 02-27-2003, 03:55 PM
  5. queued signals problem, C programming related
    By Unregistered in forum Linux Programming
    Replies: 3
    Last Post: 01-21-2002, 11:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21