| Christopher Smith on 3 Oct 2003 19:08:29 -0000 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: [ALACPP] Why won't g++ tell me I'm dumb? |
On Tue, 2003-09-30 at 12:07, Kevin Scaldeferri wrote: > We had a bit of a puzzle at lunch today, trying to figure out why my > simple test case for my simple test function was dying a horrible > death. Here's the distilled version of the code: So, I was able to fix my stupid setup problem with icc, and then compile this code again, to discover that the Intel compiler magically did the right thing. BTW, I found a couple of off-by-one type errors in the code, here's a corrected version (still won't work with g++ until you make copies of the strings, but it will work with the Intel compiler). -- Christopher Smith <x@xxxxxxxx>
#include <string.h>
#include <boost/test/included/unit_test_framework.hpp>
//#include <boost/test/unit_test.hpp>
using namespace boost::unit_test_framework;
void strrev(char* s) {
int l = strlen(s);
char tmp;
int i;
for ( i = 0 ; i < (l / 2) ; ++i ) {
tmp = s[i];
s[i] = s[l - 1 - i];
s[l - 1 - i] = tmp;
}
}
void strawman() {
BOOST_CHECK( 2 == 1 );
}
void strrevtest() {
char* t;
t = ""; strrev(t);BOOST_CHECK_EQUAL( std::strcmp(t,""), 0);
t = "a"; strrev(t);BOOST_CHECK_EQUAL( std::strcmp(t,"a"), 0);
t = "ab"; strrev(t);BOOST_CHECK_EQUAL( std::strcmp(t,"ba"), 0);
t = "asdf"; strrev(t);BOOST_CHECK_EQUAL( std::strcmp(t,"fdsa"), 0);
t = "asdfg"; strrev(t);BOOST_CHECK_EQUAL( std::strcmp(t,"gfdsa"), 0);
char a[2049];
char b[2049];
memset(a, 0, 2049);
memset(a, 0, 2049);
int i;
for ( i = 0 ; i < 2048 ; ++i ) {
a[i] = 'a' + (i % 16);
b[i] = 'a' + 15 - (i % 16);
}
strrev(a);
BOOST_CHECK_EQUAL( std::strcmp(a,b), 0);
}
test_suite*
init_unit_test_suite ( int argc, char** argv) {
test_suite* test = BOOST_TEST_SUITE( "strrev test");
/*test->add( BOOST_TEST_CASE( &strawman ));*/
test->add( BOOST_TEST_CASE( &strrevtest ));
return test;
}
_______________________________________________ alacpp mailing list alacpp@xxxxxxxxxxx http://lists.ellipsis.cx/mailman/listinfo/alacpp