Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointer Problem

Status
Not open for further replies.

Jodi999

Programmer
Feb 24, 2004
10
US
I have the following:

UINT16 ARCFOUR_Sbox[256];
VPTR ptr;

ptr = &ARCFOUR_Sbox[64];

and I get the errors:
C2109: subscript requires array or pointer type
C2102: '&' requires l-value

Does anyone know what is wrong with 'ptr = &ARCFOUR_Sbox[64];'?
 
Can you post a complete program containing just the relevant declarations, which we can all compile.

--
 
Unfortunately, I am working on a classified system and cannot post the program. I had to slightly modify the code as it is.
 
You can't rename and post half a dozen lines?

Code:
int main ( ) {
    UINT16 ARCFOUR_Sbox[256];
    VPTR ptr;
    ptr = &ARCFOUR_Sbox[64];
    return 0;
}
Add UINT16 and VPTR declarations so that it breaks your compiler, then post what you find here.
Oh, and don't forget to mention which compiler, unless that's also a secret.

--
 
Using Visual C++. Don't have compiler on unclassified network, so I don't know what you'll be missing if you try to compile.

Main.h code:

extern UINT16 ARCFOUR_Sbox;

typedef struct arcfour_state {
UINT16 ij;
UINT16 reserved;
UINT16 salt[10];
Pointer32 part0;
Pointer32 part1;
} PACKED_STRUCTURE_ATTRIBUTE_2 arcfour_state;


typedef struct arcfour_cntxt {
UINT16 config;
kcr key;
UINT16 dp_parts01;
UINT16 endian_parts01;
UINT16 dp_state;
UINT16 endian_state;
Pointer32 state;
} PACKED_STRUCTURE_ATTRIBUTE_2 arcfour_cntxt;


typedef union Pointer32 {
VPTR ptr;
ADDRESS addr;
BYTE ptr8[4];
UINT16 word16[2];
} PACKED_STRUCTURE_ATTRIBUTE_2 Pointer32;



Main.c code:

UINT16 ARCFOUR_Sbox;


void arcfour_init(void)
{
ARCFOUR_KeyId = 9999;
ARCFOUR_Dir = 0;
memset16(ARCFOUR_state, 0, 132);
ARCFOUR_Sbox = &ARCFOUR_state[4];

ARCFOUR_cntxt.state.ptr = &ARCFOUR_intstate.ij;

((arcfour_state *)(ARCFOUR_cntxt.state.ptr))->part0.ptr = ARCFOUR_Sbox;
((arcfour_state *)(ARCFOUR_cntxt.state.ptr))->part1.ptr = &ARCFOUR_Sbox[64]; /*This line gives error*/
}
 
First thing I suggest you do is turn up the warning level on your compiler to maximum, because there seems to be an awful lot of implicit casting going on.

> UINT16 ARCFOUR_Sbox;
This I'm guessing is an integal type, say something like
typedef unsigned short int UINT16;

> ARCFOUR_Sbox = &ARCFOUR_state[4];
This results in an IMPLICIT conversion of a pointer to a struct, to an unsigned short int

> ((arcfour_state *)(ARCFOUR_cntxt.state.ptr))->part0.ptr = ARCFOUR_Sbox;
This results in an IMPLICIT conversion of an unsigned short int to a pointer.
I'm guessing
typedef void * pointer32;

> &ARCFOUR_Sbox[64]; /*This line gives error*/
Yeah, ARCFOUR_Sbox is of an integral type, so its no surprise that you can't subscript it.

Well you could change the declaration to this
UINT16 *ARCFOUR_Sbox;
which would fix the immediately apparent problems with the code you posted, but I rather suspect there are wider issues at stake.

Like for instance, having done this
> &ARCFOUR_Sbox[64];
do you know that part1.ptr is 128 bytes past part0.ptr?

In your first post, you said
> UINT16 ARCFOUR_Sbox[256];
So what gives?
Posting accurate information really helps you know.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top