Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
March 25, 2003 design by contract | ||||
---|---|---|---|---|
| ||||
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 |
March 25, 2003 Re: design by contract | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jim Jennings | 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] == " << 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 > > > |
March 25, 2003 Re: design by contract | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:b5q6hb$2211$1@digitaldaemon.com... > 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? 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 |
March 25, 2003 Re: design by contract | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jim Jennings | 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 > 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? > > 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 > > > > |
March 25, 2003 Re: design by contract | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jim Jennings | 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 > 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? > > 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 > > > > |
March 25, 2003 Re: design by contract | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nic Tiger | 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 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 > > 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? > > > > 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 > > > > > > > > > > |
Copyright © 1999-2021 by the D Language Foundation