Re: VS2005 access violation on char array



I have an array defined as follows:

static CTS_PUCHAR auchKeys[] =
{
{(CTS_PUCHAR)"PCCCTEST ONTRACK"}, // 0
{(CTS_PUCHAR)"APPLN..1 ONTRACK"}, // 1
{(CTS_PUCHAR)"APPLN..2 ONTRACK"}, // 2
};

where:

typedef unsigned char CTS_UCHAR;
typedef CTS_UCHAR * CTS_PUCHAR;

In VC 6.0 I can do the following but in VS2005 it gives an access
violation
and I can't figure out why?

auchKeys[1][7] = '1';

It's illegal behaviour that you were getting away with in VC6. You can't
modify a string literal which is what you're doing here. A string literal is
an array of "const" char (or in your case "unsigned char").


.



Relevant Pages

  • Append Query key violations... Autonumber entries
    ... I'm getting a key violation message. ... You attempt to run a query that appends, deletes, or updates records in a way ... To modify records in a way that will violate referential integrity, ...
    (microsoft.public.access.queries)
  • Re: modifying string literal
    ... "Ron Natalie" wrote in message ... >> literal, which is a violation. ... In you modify the array, ...
    (comp.lang.cpp)
  • Re: modifying string literal
    ... In you're trying to modify the actual ... >> literal, which is a violation. ... In you modify the array, ... for example) as a special case when array type doesn't ...
    (comp.lang.cpp)
  • Re: Modify Static Data Okay?
    ... Your code does not modify static data. ... If you had used strcpy, e.g., ... invoke undefined behavior, not because anything is static but because ... Modifying a const object is a violation. ...
    (comp.lang.c)
  • Re: Hmm. Piracy
    ... PC but did not modify Apple's software, you would also not be in violation of ... The OS X EULA prohibits running the OS on other than Apple branded computers. ...
    (comp.sys.mac.system)