www.digitalmars.com         C & C++   DMDScript  

c++.stl.port - error with DbC

reply FUKUDA, Fumiki <FUKUDA,_member pathlink.com> writes:
#include <iostream>
#include <cassert>

int half(int n)
__in  { assert( n > 0 ); }
__out (result) { assert(result+result < n); }
__body 
{
return n/2;
}

int main() {
std::cout << "Hello, world" << half(-5) << std::endl;
return 0;
}

this code reports compile error under DMC841C+STLport
even if '-D' is NOT specified. why? what should I do?

__in  { assert( n > 0 ); }
^
foo.cpp(5) : Error: '__stl_in' is not in function par
__out (result) { assert(result+result < n); }
^
foo.cpp(6) : Error: '=', ';' or ',' expected
}
^
foo.cpp(10) : Error: '=', ';' or ',' expected
return 0;
^
foo.cpp(14) : Error: '=', ';' or ',' expected
}
^
foo.cpp(15) : Error: '=', ';' or ',' expected
Fatal error: too many errors
Oct 06 2004
next sibling parent FUKUDA, Fumiki <FUKUDA,_member pathlink.com> writes:
oops... sorry, dumpilated.
Oct 07 2004
prev sibling parent "Alan" <alan surfbest.net> writes:
<FUKUDA>; "Fumiki" <FUKUDA,_member pathlink.com> wrote in message
news:ck2pa8$s1t$1 digitaldaemon.com...
 #include <iostream>
 #include <cassert>

 int half(int n)
 __in  { assert( n > 0 ); }
 __out (result) { assert(result+result < n); }
 __body
 {
 return n/2;
 }

 int main() {
 std::cout << "Hello, world" << half(-5) << std::endl;
 return 0;
 }
Putting function half in the stream causes 'undefined behaviour' (UB), better : int main { int result = half(-5); std::cout << "result = " << result << "\n": }
Dec 26 2004