Thread: #error & #line

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    70

    #error & #line

    please can you guys tell me how to use #error and #line.

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    22
    Is this related to C. I afraid not! . Please be more specific

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Don't you have a C book? If not, I'd suggest you buy one instead of asking how to use every single function and preprocessor directive. Also, consider using a search engine, which gives you hits like this and this, also things like this here and so on, and... well, you get the idea.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by codomaniac
    Is this related to C. I afraid not! .
    Actually, it is. But it's fairly easy to find out what you need, as I've illustrated with only a bit of typing into the nearest search engine.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Is this related to C.
    It is, as a matter of fact.

    >please can you guys tell me how to use #error and #line.
    #line gives you control over the macros __LINE__ and __FILE__. Those two are most often used in error reporting, but the need to reset them may arise in tool-generated source files that need to be associated at the line level with the original user-written file. A good example would be a preprocessor that makes signifigant changes yet still requires accurate symbolic debugging on the original source file. The syntax:
    Code:
    #line n filename
    Makes changes to both __LINE__ and __FILE__. The syntax:
    Code:
    #line n
    Only makes changes to __LINE__. Here's an example:
    Code:
    #include <stdio.h>
    
    int
    main(void)
    {
      printf("This should be line 9: %d\t%s\n", __LINE__, __FILE__);
    #line 12345 "Booga!"
      printf("This would be line 11 without #line: %d\t%s\n", __LINE__, __FILE__);
    
      return 0;
    }
    #error creates a compile-time error. It's usage is pretty obvious:
    Code:
    #if !defined(SOME_MACRO)
    #  error "SOME_MACRO not defined"
    #endif
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    22
    Oh i didnt know this. Thanks for pointing this to me and Prelude you really rock

  7. #7
    ---
    Join Date
    May 2004
    Posts
    1,379
    while we are on the subject or the preprocessor,
    what does #pragma do? i have looked around but i need to see an example of how its used.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >what does #pragma do?
    In C89/90, #pragma is completely implementation dependent. For details on how it's used you need to look through your compiler's documentation. In C99, there are three standard pragmas, two for floating-point operations and one for complex number operations. Check your nearest C99 reference manual for details.
    My best code is written with the delete key.

  9. #9
    ---
    Join Date
    May 2004
    Posts
    1,379
    ok thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading a file line by line
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 03-18-2009, 11:44 PM
  2. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 09:17 PM
  3. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  4. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 05:44 PM