TypeCast Problem

Hello All

I am getting error in my below code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  const unsigned char DD[]=	
        {0x12,	       		
        0x01,			
        0x00,0x01,		
	0x00,0x00,0x00, 	
	0x40,			
	0x6A,0x0B,		
	0x46,0x53,		
	0x34,0x12,		
	1,2,3,			
	1};	
typedef unsigned char BYTE
BYTE  *pDdata;
pDdata = DD;//getting error cannot convert from 'const unsigned char [18]' to 'BYTE *' 


Please can any one let me know the solution.
unsigned char DD[]
xor
const BYTE *pDdata
closed account (2UD8vCM9)
Yo wassup my nigga Rockyy

Try this

instead of
 
pDdata = DD;


try

 
pDdata = (BYTE*)DD;



I'm not sure if these were the results you were expecting, but it seemed to work for me whenever I debugged and looked at the values for what pData was pointing to.
pDdata = (BYTE*)DD;

Do not do this. You are forcibly casting around a const problem. This is a bad cast.

ne555's solution is better: since the data is const, use a const pointer:

1
2
3
const BYTE* pDdata;

pDdata = DD;
Last edited on
@Disch
If i use the above solution the problem is that ,i am passing pDdata value to a function
Writebyte(fifo,len,pDdata);

Then my function is complaing

Writebytes' : cannot convert parameter 3 from 'const BYTE *' to 'BYTE *'
This is a const correctness problem.

If Writebytes is not modifying the data being pointed to... then it should also take a const pointer as a parameter.

(and if it is... you wouldn't be able to pass it const data no matter how you cast it)
Last edited on
closed account (j3Rz8vqX)
Exactly as Disch has stated.

Are you intending to modify DD in the function being called?

If so, your intentions of DD being constant, may not be what you want. Possibly make it non constant; declared without const.

Else, if it was meant to be constant, there would be no way to modify its contents; why would you want to modify something you determine to be constant?
Topic archived. No new replies allowed.