Reputation: 37
i am stuck in a porting of my project from VC6 to VS2010. Please can any one help me out.
void CEdchLoop::ReceiveSdu(UINT8* Sdu, UINT32 BitLength, int Fn)
{
UINT8* pPdu = Sdu;
int Bit = 8;
UINT32 SourceId = GetBitsL(pPdu, BitLength, Bit, 32);
UINT32 PduUniqueId = GetBitsL(pPdu, BitLength, Bit, 32);
}
in the above code i get error as error C2664: 'GetBitsL' : cannot convert parameter 1 from 'UINT8 *' to 'const UINT8 *&'
and GetBitsL is defined as UINT32 GetBitsL(const UINT8*& Bin, UINT32& BitLength, int& Bit, int Count)
Please can any one help me with this. i am sorry if its not a brilliant question. But to be fool for five minutes is better than being a fool forever.
Thanks in advance.
Upvotes: 0
Views: 209
Reputation: 20812
GetBitsL
requires a reference to a pointer-to-const-UINT8. You're giving it a reference to a pointer-to-volatile-UINT8, and there is no direct by-reference translation. Change pPdu
to be that by:
// UINT8* pPdu = Sdu;
const UINT8* pPdu(Sdu);
It is still initialized to point the same UINT8
as Sdu
, but now as a pointer-to-const-UINT8 which the function expects. The function can still modify the pointer, but not what it points to. (which should be a hint that you might not be using the function as design-intended, so consider that).
Upvotes: 1
Reputation: 103751
The problem is best explained with a demonstration:
int * ip;
const int *& cipr = ip;
Okay, at this point, cipr
is a reference to ip
. This is not legal, you'll see why in the following sections.
const int * cip = some_const_data;
cipr = cip;
That assignment was legal, because, being a (reference to) a pointer to const data, cipr
is allowed to be assigned to point to const data. But because of that, since cipr
is a reference to ip
, now ip
points to const data. That's a problem:
*ip = 7;
This is legal, because the type of ip
is pointer to non-const int. However, through some trickery above, we made it point to const data. That cannot be allowed, and so our initial statement, where we bound cipr
to refer to ip
must be illegal. And that's the same thing you are trying to do by passing pPdu
to GetBitsL
.
Upvotes: 1