Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,389 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,277 people online right now. Registration is fast and FREE... Join Now!




EXC_BAD_ACCESS

 
Reply to this topicStart new topic

EXC_BAD_ACCESS, what is the problem with this code

basavarajkm
7 Feb, 2008 - 01:09 AM
Post #1

New D.I.C Head
*

Joined: 30 Jan, 2008
Posts: 2

CODE
#include <iostream>
    
#define GSTR(str)  GConstString(L"  " L##str L"\0", sizeof(str)-1)
    
class GConstString
{
public:
    union
    {
        wchar_t    *pData;
        int    *pSize;
    };
    GConstString(wchar_t p[], int size)
    {
        pData = p;
        *pSize = size;  
    }
};

int main()
{
    GSTR("GFC Application Module");
    return 0;
}

User is offlineProfile CardPM
+Quote Post

Bench
RE: EXC_BAD_ACCESS
7 Feb, 2008 - 02:56 PM
Post #2

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 683



Thanked: 24 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
Where exactly did you see the message which you've described in the topic title?

union structures cause each member to share the same space in memory. This means that only one member can be active at any time, and to use another at the same time, on the same union object is undefined behaviour (And may be the root cause of your error message).
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 10:01AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month