www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - design by contract

↑ ↓ ← "Jim Jennings" <jwjenn mindspring.com> writes:
Is "design by contract implemented? I tried it with the following results:

// contr.cpp
#include <iostream>
#include <cassert>

using namespace std;  // just in case.
int main(int argc, char* argv[])
{
    __in
    {
         assert(argc == 3);
    }
    __body
    {
         std::cout<< "argv[1] == " << argv[1] << ", argv[2] == " << argv[2]
<< '\n';
    }
    return 1;
}

dmc contr -I\dm\stlport\stlport
    {
    ^
contr.cpp(9) : Error: undefined identifier '__stl_in'
    __body
         ^
contr.cpp(12) : Error: '=', ';' or ',' expected
    return 1;
         ^
contr.cpp(16) : Error: '=', ';' or ',' expected
}
^
contr.cpp(17) : Error: identifier or '( declarator )' expected
--- errorlevel 1
Mar 25 2003
↑ ↓ "Walter" <walter digitalmars.com> writes:
It is implemented. Unfortunately, stl uses __in and __out as variable names,
which conflict with the keywords, so they are #defined to be __stl_in and
__stl_out. You can #undef __in and #undef __out after #including the stlport
files.

"Jim Jennings" <jwjenn mindspring.com> wrote in message
news:b5q3ih$1vmd$1 digitaldaemon.com...
 Is "design by contract implemented? I tried it with the following results:

 // contr.cpp
 #include <iostream>
 #include <cassert>

 using namespace std;  // just in case.
 int main(int argc, char* argv[])
 {
     __in
     {
          assert(argc == 3);
     }
     __body
     {
          std::cout<< "argv[1] == " << argv[1] << ", argv[2] == " <<

 << '\n';
     }
     return 1;
 }

 dmc contr -I\dm\stlport\stlport
     {
     ^
 contr.cpp(9) : Error: undefined identifier '__stl_in'
     __body
          ^
 contr.cpp(12) : Error: '=', ';' or ',' expected
     return 1;
          ^
 contr.cpp(16) : Error: '=', ';' or ',' expected
 }
 ^
 contr.cpp(17) : Error: identifier or '( declarator )' expected
 --- errorlevel 1

Mar 25 2003
↑ ↓ "Jim Jennings" <jwjenn mindspring.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:b5q6hb$2211$1 digitaldaemon.com...
 It is implemented. Unfortunately, stl uses __in and __out as variable

 which conflict with the keywords, so they are #defined to be __stl_in and
 __stl_out. You can #undef __in and #undef __out after #including the

 files.

 "Jim Jennings" <jwjenn mindspring.com> wrote in message
 news:b5q3ih$1vmd$1 digitaldaemon.com...
 Is "design by contract implemented?


Now I get this: (DBC is low priority, It looked simpler than all the "try ... catch" bloat) // contr.cpp #include <iostream> #include <cassert> #undef __in #undef __out using namespace std; // just in case. int main(int argc, char* argv[]) { __in { assert(argc == 3); } __body { std::cout<< "argv[1] == " << argv[1] << ", argv[2] == " << argv[2] << '\n'; } return 1; } dmc contr -I\dm\stlport\stlport __in ^ contr.cpp(9) : Error: '=', ';' or ',' expected __body ^ contr.cpp(13) : Error: '=', ';' or ',' expected } ^ contr.cpp(17) : Error: identifier or '( declarator )' expected return 1; ^ contr.cpp(18) : Error: '=', ';' or ',' expected } ^ contr.cpp(19) : Error: identifier or '( declarator )' expected Fatal error: too many errors --- errorlevel 1
Mar 25 2003
"Nic Tiger" <nictiger progtech.ru> writes:
Right syntax is:

----------------------------------
#include <iostream>
#include <cassert>
#undef __in
#undef __out

using namespace std;  // just in case.

int main(int argc, char* argv[])
__in
{
     assert(argc == 3);
}
__body
{
 std::cout<< "argv[1] == " << argv[1]
    << ", argv[2] == " << argv[2] << '\n';
 return 1;
}
----------------------------------------------
Note that __in, __out and __body sections follow right after function header
(not in {} braces).

And mention that you should specify -D switch (sc -D dbc.cpp). For me it
doesn't work with STL (linker issues errors about unresolved names).

Nic Tiger.

"Jim Jennings" <jwjenn mindspring.com> сообщил/сообщила в новостях
следующее: news:b5q96h$23sl$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:b5q6hb$2211$1 digitaldaemon.com...
 It is implemented. Unfortunately, stl uses __in and __out as variable

 which conflict with the keywords, so they are #defined to be __stl_in


 __stl_out. You can #undef __in and #undef __out after #including the

 files.

 "Jim Jennings" <jwjenn mindspring.com> wrote in message
 news:b5q3ih$1vmd$1 digitaldaemon.com...
 Is "design by contract implemented?


Now I get this: (DBC is low priority, It looked simpler than all the "try ... catch" bloat) // contr.cpp #include <iostream> #include <cassert> #undef __in #undef __out using namespace std; // just in case. int main(int argc, char* argv[]) { __in { assert(argc == 3); } __body { std::cout<< "argv[1] == " << argv[1] << ", argv[2] == " << argv[2] << '\n'; } return 1; } dmc contr -I\dm\stlport\stlport __in ^ contr.cpp(9) : Error: '=', ';' or ',' expected __body ^ contr.cpp(13) : Error: '=', ';' or ',' expected } ^ contr.cpp(17) : Error: identifier or '( declarator )' expected return 1; ^ contr.cpp(18) : Error: '=', ';' or ',' expected } ^ contr.cpp(19) : Error: identifier or '( declarator )' expected Fatal error: too many errors --- errorlevel 1

Mar 25 2003
↑ ↓ → "Jim Jennings" <jwjenn mindspring.com> writes:
Thank you, Walter and Nic, It works now.
Jim J.
P.S. I am positive that I tried that, and it complained about not having a
closing brace. I probably put a left brace in instead of a right brace.
careless!

"Nic Tiger" <nictiger progtech.ru> wrote in message
news:b5qf9c$28g6$1 digitaldaemon.com...
 Right syntax is:

 ----------------------------------
 #include <iostream>
 #include <cassert>
 #undef __in
 #undef __out

 using namespace std;  // just in case.

 int main(int argc, char* argv[])
 __in
 {
      assert(argc == 3);
 }
 __body
 {
  std::cout<< "argv[1] == " << argv[1]
     << ", argv[2] == " << argv[2] << '\n';
  return 1;
 }
 ----------------------------------------------
 Note that __in, __out and __body sections follow right after function

 (not in {} braces).

 And mention that you should specify -D switch (sc -D dbc.cpp). For me it
 doesn't work with STL (linker issues errors about unresolved names).

 Nic Tiger.

 "Jim Jennings" <jwjenn mindspring.com> сообщил/сообщила в новостях
 следующее: news:b5q96h$23sl$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:b5q6hb$2211$1 digitaldaemon.com...
 It is implemented. Unfortunately, stl uses __in and __out as variable

 which conflict with the keywords, so they are #defined to be __stl_in


 __stl_out. You can #undef __in and #undef __out after #including the

 files.

 "Jim Jennings" <jwjenn mindspring.com> wrote in message
 news:b5q3ih$1vmd$1 digitaldaemon.com...
 Is "design by contract implemented?


Now I get this: (DBC is low priority, It looked simpler than all the


 ... catch" bloat)

 // contr.cpp
 #include <iostream>
 #include <cassert>
 #undef __in
 #undef __out
 using namespace std;  // just in case.
 int main(int argc, char* argv[])
 {
     __in
     {
          assert(argc == 3);
     }
     __body
     {
          std::cout<< "argv[1] == " << argv[1]
             << ", argv[2] == " << argv[2] << '\n';
     }
     return 1;
 }

 dmc contr -I\dm\stlport\stlport
     __in
        ^
 contr.cpp(9) : Error: '=', ';' or ',' expected
     __body
          ^
 contr.cpp(13) : Error: '=', ';' or ',' expected
     }
     ^
 contr.cpp(17) : Error: identifier or '( declarator )' expected
     return 1;
          ^
 contr.cpp(18) : Error: '=', ';' or ',' expected
 }
 ^
 contr.cpp(19) : Error: identifier or '( declarator )' expected
 Fatal error: too many errors
 --- errorlevel 1


Mar 25 2003
→ "Walter" <walter digitalmars.com> writes:
Rewrite the function body as:

int main(int argc, char* argv[])
__in
{
         assert(argc == 3);
}
__body
{
         std::cout<< "argv[1] == " << argv[1]
            << ", argv[2] == " << argv[2] << '\n';
     return 1;
}


"Jim Jennings" <jwjenn mindspring.com> wrote in message
news:b5q96h$23sl$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:b5q6hb$2211$1 digitaldaemon.com...
 It is implemented. Unfortunately, stl uses __in and __out as variable

 which conflict with the keywords, so they are #defined to be __stl_in


 __stl_out. You can #undef __in and #undef __out after #including the

 files.

 "Jim Jennings" <jwjenn mindspring.com> wrote in message
 news:b5q3ih$1vmd$1 digitaldaemon.com...
 Is "design by contract implemented?


Now I get this: (DBC is low priority, It looked simpler than all the "try ... catch" bloat) // contr.cpp #include <iostream> #include <cassert> #undef __in #undef __out using namespace std; // just in case. int main(int argc, char* argv[]) { __in { assert(argc == 3); } __body { std::cout<< "argv[1] == " << argv[1] << ", argv[2] == " << argv[2] << '\n'; } return 1; } dmc contr -I\dm\stlport\stlport __in ^ contr.cpp(9) : Error: '=', ';' or ',' expected __body ^ contr.cpp(13) : Error: '=', ';' or ',' expected } ^ contr.cpp(17) : Error: identifier or '( declarator )' expected return 1; ^ contr.cpp(18) : Error: '=', ';' or ',' expected } ^ contr.cpp(19) : Error: identifier or '( declarator )' expected Fatal error: too many errors --- errorlevel 1

Mar 25 2003