Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7083335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:09:55+00:00 2026-05-28T07:09:55+00:00

The next pattern is common in C code: #ifndef SOMETHING #define SOMETHING #endif The

  • 0

The next pattern is common in C code:

#ifndef SOMETHING
#define SOMETHING
#endif

The pattern is possible in Delphi code too:

{$IFNDEF SOMETHING}
{$DEFINE SOMETHING}
{$ENDIF}

but it is not common – I have never seen it at all. If a Delphi code requires a conditional define, it just defines it without IFNDEF check.

Why so? What is the difference in conditional compilation between C and Delphi so that ifndef check is needed for former and not needed for latter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:09:56+00:00Added an answer on May 28, 2026 at 7:09 am

    That’s because this is not only common but mandatory in C:

    #include <something.h>
    

    While this is rarely used in Delphi. And when used, it’s actually used to set up those {$DEFINE} ‘s:

    {$INCLUDE 'something.inc'}
    

    This matters because DEFINES are only valid while compiling one object (may it be a .PAS file or a .C file). Delphi uses the uses clause to include other units, while C uses the include to include it’s headers. In C headers might themselves include other headers. The pattern you’re asking about is used to prevent recursively re-including the same header.

    To make maters crystal-clear, here’s a sample of what one might use in C, and the equivalent in Delphi. Let’s say we’ve got a 3 files setup, where A needs to include both B and C, and B only needs to include C. The “C” files would look like this:

    // ----------------------- A.h
    #ifndef A
    #define A
    
    #include "B.h"
    #include "C.h"
    
    // Stuff that goes in A
    
    #endif
    
    // ------------------------ B.h
    #ifndef B
    #define B
    
    #include "C.h"
    
    // Stuff that goes in B
    
    #endif
    
    // ----------------------- C.h
    #ifndef C
    #define C
    
    // Stuff that goes in C
    
    #endif
    

    Without the conditional defines in C.h, the C.h file would end up being included twice in A.h. This is how the code would look like in Delphi:

    // --------------------- A.pas
    unit A;
    
    interface
    
    uses B, C;
    
    implementation
    
    end.
    
    // --------------------- B.pas
    unit B
    
    interface
    
    uses C;
    
    implementation
    
    end.
    
    // --------------------- C.pas
    
    unit C
    
    interface
    
    implementation
    
    end.
    

    The Delphi/Pascal version doesn’t need to protect “C” from being included twice in “A” because it doesn’t use the {$INCLUDE} to achieve this goal, it use the uses statement. The compiler would get the exported symbols from the B.dcu file and the C.dcu files with no risk of including symbols from C.dcu twice.


    Other reasons to see a lot more precompiler directives in C code:

    • The precompiler is a lot more powerful then Delphi’s. A {$DEFINE} in Delphi code only deals with conditional compilation, while the C variant can be used for both conditional compilation and as a form of word substitution.
    • The mandatory use of #include for headers means you can have a header that defines macros. Or you can have a header that’s configured by specifying some #define statements before the actual #include <header.h>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have occasionally encountered a pattern in code which resembles a monad but does
The next code runs normally in SQLSERVER but when i change the web.config to
I may have the wrong pattern here, but I think it's a fair topic.
I have next code: public static void createTokens(){ String test = test is a
What is the closest design pattern for something like an issue tracker? You have
I remapped [[ and ]] to find the previous and next pattern in the
I have the next function: function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName(img); for(var i
Why next code returns true (Saxon-EE 9.2 for .NET)? matches('some text>', '^[\w ]{3,200}$') There
I have this pattern where I need to select any random element from a
I have a need to assign the next sequence number for a Project according

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.