Mail Archives: djgpp/1999/09/07/19:57:59
In article <37d4ce7c DOT 0 AT news DOT uni-bielefeld DOT de>, Manni Heumann
<manfred DOT heumann AT uni-bielefeld DOT de> writes
[snip - no 'const' in Allegro]
>But the problem is there anyway. It's either the developer or the user of the
>library who has to deal with it. And since 2.95 it got serious, because
>sources that pass something supposed to be const to a non-const function will
>no longer compile.
- cut here -------------------------------------------------------------
#include <iostream>
#include <cstring>
void test0(const char const*&) throw();
void test1(char*&) throw();
int main()
{
char* Q = new char[30];
strcpy(Q, "Hello, C++ world!");
cout << "Before test0: " << Q << endl;
test0(Q);
cout << "After test0: " << Q << endl;
delete [] Q;
}
void test0(const char const*& Q) throw()
{
test1(Q);
}
void test1(char*& Q) throw()
{
delete [] Q;
Q = new char[30];
strcpy(Q, "Hello again, C++ world!");
}
- cut here -------------------------------------------------------------
> gxx -fpermissive -o const.exe const.cpp
> const
Before test0: Hello, C++ world!
After test0: Hello again, C++ world!
>So if you are programming in C++ and use strings you will have to resort to
>some ugly hacks in your code.
The code itself is unaffected if you use -fpermissive. Of course, it
will compile with warnings, and does enable you to do silly things:
string s;
do_uconvert("don't try this at home", U_ASCII, s.c_str(), U_UTF8, 99);
This will overwrite memory that does not belong to s.
>It seems the problem really is in the varargs macros and Shawn is off the
>hook, so the question seems to be what the C++ guys want to do about all this.
>Suggestions, anybody?
If you are using C++ string objects, you don't really need to use
Allegro's varargs stuff, because you can use strstream objects, etc.
Although I admit allegro_message() might be fundamental to a program.
If you are willing to wait, I'm trying to write a set of C++ wrappers
for Allegro which will, at least, solve the lack of const problems.
Whether making the Allegro sources const-correct would be worthwhile, or
even possible, I'll leave to somebody more experienced to decide.
HTH, and bye for now,
--
Laurence Withers, lwithers AT lwithers DOT demon DOT co DOT uk
http://www.lwithers.demon.co.uk/
- Raw text -