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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:59:11+00:00 2026-05-27T06:59:11+00:00

I have a dll or shared object, MyDll which produces an object, ForeignObject: class

  • 0

I have a dll or shared object, MyDll which produces an object, ForeignObject:

class ForeignObject : public LocalInterface {
  virtual void some_func(Injector& i) {
    i.inject();
  }
};

In the interfaces looks like this.

class Injector {
  virtual void inject() = 0;
};

class LocalInterface {
  virtual void some_func(Injector& i) = 0;
};

Then I do the following:

class MyInjector : public Injector {
  virtual void inject() {throw std::runtime_error("arrgghh");}
};

int main() {
  LocalInterface* foreign_obj = create_object_from_my_dll();
  MyInjector injector;
  foreign_obj->some_func(injector);
  destroy_object_from_my_dll(foreign_obj);
  return 0;
}

My question is, why is it safe/not safe to throw an exception like this. Is it safe when they are built with the same compiler? Between compilers?

  • 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-27T06:59:12+00:00Added an answer on May 27, 2026 at 6:59 am

    I would say the answer will depend on the OS. But for all the UNICES I’ve worked with (including Linux and Mac OS X), it will be safe. Of course, you need to compile with compilers using the same ABI, but the ABI of g++ hasn’t changed in years (can’t remember exactly, but I think 3.2 was the last big change). Also, in the model used in Linux, linkage don’t impact code behaviour. So you can safely put any code in a dynamically linked file (i.e. shared object file), it will work as if it is linked statically.

    On Windows, if you use VC++, then you won’t be able to compile your library with another compiler. The program and the library must use the same version of VC++, there is no compatibility in either direction. If you are using g++, you can compile with another version of g++ (like on UNIX), but not with VC++. As for the question of it this is dangerous, I will let a windows-specialist answer as DLL have weird behaviour, and if I remember an object should always be destroyed within the scope of the DLL that loaded it, but I am not 100% sure.

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

Sidebar

Related Questions

I have a C library, which I build as a shared object for Linux
I have a shared object (dll). How do I find out what all symbols
I have a shared dll which is built in 32 bit and 64 bit.
The situation is this: I have a shared (DLL) build of Qt 4.5.1 and
I have a dll that contains a templated class. Is there a way to
I have a shared object (a so - the Linux equivalent of a Windows
I have the current code: Public Declare Function FindWindow Lib user32.dll Alias FindWindowA (ByVal
I had a discussion today about refactoring this (#1) public void MyFunc(object myArgument) {
I have an API (a DLL) which has various methods that return objects /
We have a DLL project which has existed for a long time (maybe as

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.