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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:33:34+00:00 2026-06-09T08:33:34+00:00

I am trying to use some software which has been written in C++ in

  • 0

I am trying to use some software which has been written in C++ in a separate C program.

I have compiled the necessary components within a .lib file, and included some C code using

#ifdef __cplusplus
    extern "C" {
#endif

This code sort of wraps up the C++ object method calls within C callable functions. The objects are declared in file scope, and pointers to the objects are retreived initially and then later used to reference which object to call the method on. For example:

const void *GetHandle() {
    return (void *) &obj;
}

And then to call a method:

int GetInt(const void *handle) {
    Object *temp = (Object *) handle;
    return temp->getInt();
}

Is this a valid solution to the problem? At the moment, with just the GetHandle() methods in my C program, I get errors saying “error C2099: initializer is not a constant” when I try to assign their return values to some const void * variables.


EDIT

Fixed the problem. My ignorance of standard C bears itself here. I am used to Microchip C30 for dsPIC, which is a little different.

I was trying to both declare and initialize the pointers outside of any function. I did have them set as const but that’s not really necessary, so I now just declare outside and then initialize in an init function. I also put extern “C” in front of all the functions in the cpp file, and it all compiles now. So, thanks to everyone for the help!

  • 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-09T08:33:36+00:00Added an answer on June 9, 2026 at 8:33 am

    This is a valid solution.

    You might want to check the constness of your argument/return values/casts more carefully though.

    For example, if the object itself is not const, then GetHandle should return void *, not const void *. Same way, if getInt is a const function, then GetInt correctly gets a const void *. However, it should also cast it to const Object *, not Object *.

    For further diagnosis, you should provide the exact line you get the initializer is not a constant error (and the context where the function is called). My guess is that the error is related to some other part of your code, using these incorrectly cast values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to configure an installer for some software we use within the company.
I'm trying to use this http://www.rcsb.org/pdb/software/rest.do REST services with Qt. I did some get
I have an application I wrote which has been running well for 4 years.
I am trying to solve which design pattern I have to use for this
I have been given some 'reports' from another piece of software that contains data
I'm trying to compile some software I've been writing in Linux that uses some
I have been trying to do build and use OpenCV 2.3.0 on my Fedora15
I'm trying to use sprof to profile some software (ossim) where almost all the
I am trying to use some parameters in my sql query like this; Answer_table
I am trying to use some Word 2007 automation where we give the user

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.