Results 1 to 3 of 3

Thread: What is the disadvantage of #define?

  1. #1
    Join Date
    Nov 2012
    Location
    Artesia, CA
    Posts
    10
    Rep Power
    0

    What is the disadvantage of #define?

    Hi,

    Can somebody tell me what is the disadvantage of #define? and what do u mean by run time error and compile time error??

  2. #2
    Join Date
    Apr 2013
    Location
    Malaysia
    Posts
    12
    Rep Power
    0
    #define or a macro is not typed. It has no data type and it can lead to serious errors if not used carefully in your programs. The increase the compile time of a program.They are also difficult to debug.

    Compile time errors are those which are encountered during its compilation by the compiler itself. Like using an undeclared variable.
    Run time errors are those which are encountered during execution of a program. Compiler has no knowledge of them. Like referencing illegal memory or a null pointer.

  3. #3
    Join Date
    Apr 2019
    Location
    Ahmedabad
    Posts
    29
    Rep Power
    0
    Disadvantages of #define
    1. It is not type safe.
    2. It replaces the code that follows in the main program where ever they are referred to.Thus, Compile time is increased.
    3. Need to care for parenthesis.
    4. May not store variable in symbol table.
    5. Any changes in macro , need to re-compile all source code.
    6. Preprocessor hard code #define variable. Code size become bulky


    Compile Time error : Error encountered while compiling program by compiler, like syntax error, type checking errors etc.
    Code:
    void main() { 
        int x = 10; 
        int y = 5;  
        printf("%d", (x/y))   // Syntax error as Semi-colon is missing
    }
    Run time Error : Error encountered at time of executing program by operating system, like logical error, referencing null pointer, insufficient memory for allocation etc.
    Code:
    void main() { 
        int x = 10; 
        int y = 0;  
        printf("%d", (x/y));  //Logical error as cant divide by zero
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do you define?
    By Robinalex in forum Affiliate Marketing
    Replies: 3
    Last Post: 25-12-2009, 10:17 AM
  2. How Can We Define Stickers?
    By muqtada123 in forum Other Webmaster-related Services and Promotion
    Replies: 0
    Last Post: 17-11-2009, 03:37 AM
  3. Define a Web Master
    By dannyfoo in forum Member Introductions
    Replies: 5
    Last Post: 15-05-2007, 12:42 AM
  4. #define class error dlm java prog
    By ymhy_80 in forum Website Programming
    Replies: 6
    Last Post: 14-02-2004, 12:01 AM
  5. Define: nukePHP
    By Acid-kiD in forum Website Programming
    Replies: 0
    Last Post: 29-04-2002, 01:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112