home *** CD-ROM | disk | FTP | other *** search
- #include "testlib.h"
-
- /* Compile with -b, each string should be 0-terminated. */
-
- char *str1, *str2, *str3;
-
- test_dash_b_1()
- {
- str2 = "bazz";
- str1 = "foo";
- str3 = "bar";
- itesteq(__LINE__, 0, str1[3]);
- itesteq(__LINE__, 'z', str2[3]);
- itesteq(__LINE__, 0, str2[4]);
- }
-
- int fn(char *), fn2(char *);
-
- test_dash_b_2()
- {
- itesteq(__LINE__, 45, fn("goodbye"));
- itesteq(__LINE__, 89, fn2("mundo"));
- }
-
- /* Test handling of local static objects containing strings. */
-
- struct smallstruct { char *key; int value; };
-
- fn(char *str)
- {
- int i;
- static struct smallstruct stringlist[] =
- { {"hello", 23}, {"goodbye", 45}, {"mundo", 89}};
-
- for (i = 0; i < 3; ++i) {
- if (strcmp(str, stringlist[i].key) == 0) return stringlist[i].value;
- }
- return 0;
- }
-
- int
- main()
- {
- curtestfile = __FILE__;
- test_dash_b_1();
- test_dash_b_2();
- summary();
- return 0;
- }
-
- #pragma segment seg2
-
- fn2(char *str)
- {
- int i;
- static struct smallstruct stringlist[] =
- { {"hello", 23}, {"goodbye", 45}, {"mundo", 89}};
-
- for (i = 0; i < 3; ++i) {
- if (strcmp(str, stringlist[i].key) == 0) return stringlist[i].value;
- }
- return 0;
- }
-