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 7739965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:39:19+00:00 2026-06-01T08:39:19+00:00

I am writing a program to assemble code for another dynamic program written in

  • 0

I am writing a program to assemble code for another dynamic program written in the OpenCL language. For the purpose of this question, let’s just assume the dynamic program language is C99 with the restriction that all code must be brought into a single compilation block.

My larger program determines a sequence of steps that will occur in the main function and which C99 source files are needed to implement those steps. It then invokes a C99 preprocessor / compiler to produce the dynamic program executable. I can supply the compiler macro definitions using the -D SYMBOL=defn calling argument.

Here is an example scheme that works for me and avoids diving into utilizing a separate pre-processing library or other hefty string manipulation tools. I would dynamically create the string listed as mainfile.c, the other included files would actually exist.

Is there any way I can combine the separate declaration and definition files into one file?

// mainfile.c
#include "ParentDeclarationFile.txt"
#include "ChildDeclarationFile.txt"
#include "ParentDefinitionFile.txt"
#include "ChildDefinitionFile.txt"

int main()
{
    return aFunctionParent( 5 );
}

// ParentDeclarationFile.txt
typedef float Type1;
int aFunctionParent( Type1 t );

// ChildDeclarationFile.txt
int aFunctionChild( Type1 t );


// ParentDefinitionFile.txt
int aFunctionParent( Type1 t ) { return aFunctionChild( t ); }

// ChildDefinitionFile.txt
int aFunctionChild( Type1 t ) { return 2*t; }

I’d like to have a single file like this that I can #include twice.

// SingleParentFile.txt
#ifdef DECLARATION_MODE
    //declarations here
#else
    // definitions here
#endif

but #define definitions do not pass into #include’d files ( edit: tured out to be incorrect. )and supplied -D definitions can’t change in the middle of pre-processing. Right?
Is there any sort of preprocessor state variable that I could permute after the first pass?

Note: I tried to provide a simplified example that requires the declaration and definition sections appear in separate code locations. The intent of my question is not to find a way around that in this simple example.

  • 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-06-01T08:39:20+00:00Added an answer on June 1, 2026 at 8:39 am

    One simple solution would be to #define a macro to distinguish the declaration from definition sections in the code. The #define DOES propagate to the #include files.

    // mainfile.c
    #define DECLARATION_MODE
    #include "ParentFile.txt"
    #include "ChildFile.txt"
    #undef DECLARATION_MODE
    #include "ParentFile.txt"
    #include "ChildFile.txt"
    
    int main()
    {
        return aFunctionParent( 5 );
    }
    
    // ParentFile.txt
    #ifdef DECLARATION_MODE
        typedef float Type1;
        int aFunctionParent( Type1 t );
    #else
        int aFunctionParent( Type1 t ) { return aFunctionChild( t ); }
    #endif
    
    // ChildFile.txt
    #ifdef DECLARATION_MODE
        int aFunctionChild( Type1 t );
    #else
        int aFunctionChild( Type1 t ) { return 2*t; }
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a plug-in for another program through an API. To save it's current
The title pretty much sums this up. I am writing a program in 32-bit
I just figured this out but instead of splitting my new question (why?) into
I am writing a program in assembly and it isn't working, so I'd like
Im writing a program that should read input via stdin, so I have the
I'm writing a program that sends an email out at a client's specific local
I am writing a program which has two panes (via CSplitter ), however I
If you are writing a program that is executable from the command line, you
I'm writing a program (for Mac OS X, using Objective-C) and I need to
I'm writing a program to read from a POP3 mailbox and upload the email

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.