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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:52:18+00:00 2026-06-15T23:52:18+00:00

while writing native c++ code and i see same programme works fine in xcode(iOS),

  • 0

while writing native c++ code and i see same programme works fine in xcode(iOS), though crashes in eclipse(android). I could find the problem code and that was due a bad memory access. I wonder why xcode(iOS) didn’t hit the same bad access hence crash.

Actually i created a class say “class_A” which inherits other class say class_B. Later in the code i created the same class instance pointer and assigned the return object of function foo() (belongs to class_B) which returns the object of type super class i.e class_B.

code snippet …

class class_A : public class_B
{
public:

};

class_A *tempPart = (class_A *)class_A::foo("abc.png"); 

if(tempPart)
                {


                    -------------------
                   --------------------

 }

Now, while accessing _tempPart the programme crashes for android (eclipse), however xcode(iOS) always works fine. I could figure out that as fn foo() returns the object of type class_B hence i was assigning a super class(smaller size object) class_B’s object to inherited class (a bigger size object) Class_A’s object hence it was causing a bad memory access.

But i couldn’t figure out why the same issue is not seen on xcode(iOS).
i am new to xcode and c++, so please help me to understand this.

  • 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-15T23:52:19+00:00Added an answer on June 15, 2026 at 11:52 pm

    Undefined behavior is undefined.

    Doing things like accessing invalid memory results in undefined behavior in C++. The result may often be a crash, but C++ doesn’t guarantee such things. Instead the program may simply behave oddly, or even exactly as you intended with no indication of an error. Different implementations may do different things.

    Here’s some info that may help explain why C++ has undefined behavior (as opposed to languages like Java which work very hard to rule out undefined behavior).

    What Every C Programmer Should Know About Undefined Behavior

    • Part 1
    • Part 2
    • Part 3

    It’s not entirely clear from your description what’s really going wrong. You say something about assigning a bigger object to a smaller object causing bad memory access, however that’s not the way assignment in C++ works, and the example code is using pointers anyway. The following code is completely legal and well defined, for example:

    struct B {};
    struct D : B {
      int i;
      void foo() { i = 100; }
    };
    
    B b = D(); // works fine, does not overwrite anything outside b. Slicing occurs.
    
    B *bar() {
      return new D;
    }
    
    D *d = (D*)bar(); // works fine because the dynamic type matches.
    

    Where a problem occurs is:

    B *baz() { return new B; }
    
    D *d = (D*)baz(); // not okay, undefined behavior. Anything can happen now, later, or even before this point.
    d->foo(); // might crash, might not.
    

    So, assuming this is what your program is doing, the same error in Java is well defined to cause an exception. In Objective-C the message passing machinery will try to find an implementation for the selector at runtime and if it does not find anything then an ‘unrecognized selector’ exception occurs.

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

Sidebar

Related Questions

Sometimes while writing Java in Eclipse, I write code that generates warnings. A common
I'm trying to see how drag & drop works in native javascript. I'm writing
While writing some C code, I decided to compile it to assembly and read
While writing code in a file that would comprise of PHP, HTML, CSS &
While writing code, it is pretty common to request a page with an appended
I'm developing an application separately for both Android and iOS using their native SDKs.
im writing an application that uses only native code. So is it possible to
I'm writing some native C++ code which needs to be called from C# (and
I am writing a native iPhone and Android app using Sencha Touch inside Phonegap
I'm writing an editor for large archive files (see below) of 4GB+, in native&managed

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.