 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Muzaffar Mahkamov Guest
|
Posted: Tue Dec 06, 2005 10:56 am Post subject: navigating const arrays |
|
|
Hi,
I'm trying to compile Botan encryption library in Borland C++ Builder 6.
Mostly I have problems with functions that increment pointers to
const arrays.
void MD2::add_data(const byte input[], u32bit length)
{
buffer.copy(position, input, length);
if(position + length >= HASH_BLOCK_SIZE)
{
hash(buffer.begin());
input += (HASH_BLOCK_SIZE - position); // the compilation fails
here, cannot modify const object
length -= (HASH_BLOCK_SIZE - position);
while(length >= HASH_BLOCK_SIZE)
{
hash(input);
input += HASH_BLOCK_SIZE; // also fails here
length -= HASH_BLOCK_SIZE;
}
buffer.copy(input, length);
position = 0;
}
position += length;
}
Microsoft Visual C++ 7.0 compiler does not fail. I think, the Borland
compiler shouldn't too, because i'm not modifying the array contents,
i'm modifying the pointer (which is not const).
The only quick solution came to my mind was removing the "const"
modifier using the const_cast. Removing the "const" modifier from all
the functions would take much longer time.
void MD2::add_data(const byte input2[], u32bit length)
{
byte* input = const_cast<byte*>(input2);
buffer.copy(position, input, length);
if(position + length >= HASH_BLOCK_SIZE)
{
hash(buffer.begin());
input += (HASH_BLOCK_SIZE - position);
length -= (HASH_BLOCK_SIZE - position);
while(length >= HASH_BLOCK_SIZE)
{
hash(input);
input += HASH_BLOCK_SIZE;
length -= HASH_BLOCK_SIZE;
}
buffer.copy(input, length);
position = 0;
}
position += length;
}
Is there a more elegant (and correct) solution to this problem? What do
the standards say about this issue?
Thanks in advance,
Muzaffar
|
|
| Back to top |
|
 |
Chris Uzdavinis (TeamB) Guest
|
Posted: Tue Dec 06, 2005 4:28 pm Post subject: Re: navigating const arrays |
|
|
Muzaffar Mahkamov <muzaffar (AT) design (DOT) uz> writes:
| Quote: | Hi,
I'm trying to compile Botan encryption library in Borland C++ Builder
6. Mostly I have problems with functions that increment pointers to
const arrays.
void MD2::add_data(const byte input[], u32bit length)
|
I wonder if it would work if you change the function signature to
this:
| Quote: | void MD2::add_data(const byte * input, u32bit length)
|
? (Sorry, I can't test right now, but the problem you describe sounds
strange indeed.)
--
Chris (TeamB);
|
|
| Back to top |
|
 |
Alex Bakaev [TeamB] Guest
|
Posted: Tue Dec 06, 2005 4:51 pm Post subject: Re: navigating const arrays |
|
|
Muzaffar Mahkamov wrote:
| Quote: | Hi,
I'm trying to compile Botan encryption library in Borland C++ Builder 6.
Mostly I have problems with functions that increment pointers to const
arrays.
|
There are a few const-related bugs in the compiler...
..a
|
|
| Back to top |
|
 |
Muzaffar Mahkamov Guest
|
Posted: Tue Dec 06, 2005 5:10 pm Post subject: Re: navigating const arrays |
|
|
Chris Uzdavinis (TeamB) wrote:
| Quote: |
I wonder if it would work if you change the function signature to
this:
void MD2::add_data(const byte * input, u32bit length)
? (Sorry, I can't test right now, but the problem you describe sounds
strange indeed.)
|
I'll test it tomorrow on the original sources and report.
|
|
| Back to top |
|
 |
Muzaffar Mahkamov Guest
|
Posted: Wed Dec 07, 2005 7:54 am Post subject: Re: navigating const arrays |
|
|
Chris Uzdavinis (TeamB) wrote:
| Quote: | Muzaffar Mahkamov <muzaffar (AT) design (DOT) uz> writes:
I wonder if it would work if you change the function signature to
this:
void MD2::add_data(const byte * input, u32bit length)
|
Yeah, that did the trick. Now it compiles fine (had to change both in
..cpp and .h files). Thanks for the tip.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|