]> git.sur5r.net Git - cc65/blobdiff - test/ref/pointer2.c
remote TABs in doc/ and test/
[cc65] / test / ref / pointer2.c
index d8c064ef3fbbfc36991fb4dbe36c3d6ef45273a0..cfa38426835b6e15b0cc3960cba18f59615e9963 100644 (file)
-/*\r
-  !!DESCRIPTION!! pointer test\r
-  !!ORIGIN!!\r
-  !!LICENCE!!     public domain\r
-*/\r
-\r
-#include "common.h"\r
-#include <stdio.h>\r
-\r
-/*\r
-  check behaviour on incompletely declared arrays\r
-*/\r
-\r
-char i1[];\r
-\r
-void test1(void) {\r
-int a;\r
-\r
-       a=sizeof(i1[0]);\r
-       printf("%04x - ",a);\r
-       if(sizeof(i1[0])==sizeof(char)) {\r
-               /* gcc gives size of element */\r
-               printf("sizeof(i1[0]) gives size of element\n");\r
-       }\r
-       if(sizeof(i1[0])==sizeof(char*)) {\r
-               printf("sizeof(i1[0]) gives size of pointer to element\n");\r
-       }\r
-}\r
-\r
-/*\r
-  check behaviour on string init\r
-*/\r
-\r
-char t1[]="abcde";\r
-char t2[]={"abcde"};\r
-\r
-char *t3="abcde";\r
-char *t4={"abcde"};\r
-\r
-void test2(void) {\r
-char c1,c2,c3,c4;\r
-int i,e=0;\r
-       for(i=0;i<5;i++){\r
-               c1=t1[i];c2=t2[i];c3=t3[i];c4=t4[i];\r
-/*             printf("%02x %02x %02x %02x\n",c1,c2,c3,c4); */\r
-               printf("%c %c %c %c\n",c1,c2,c3,c4);\r
-               if(!((c1==c2)&(c1==c3)&(c1==c4))) e=1;\r
-       }\r
-       if(e) printf("test2 failed.\n");\r
-       else printf("test2 ok.\n");\r
-}\r
-\r
-/*\r
-  check behaviour on extern-declarations inside functions\r
-*/\r
-\r
-typedef struct {\r
-  char *name;\r
-  void *func;\r
-} A3;\r
-\r
-#ifdef NO_SLOPPY_STRUCT_INIT\r
-A3 a3[] = {\r
-  { "test3", (void*) NULL },\r
-  { "test3", (void*) NULL },\r
-};\r
-#else\r
-/*gcc warning: missing braces around initializer (near initialization for `a3[0]')\r
-  this type of struct-initialization seems to be kinda common */\r
-A3 a3[] = {\r
-    "test3", (void*) NULL  ,\r
-    "test3", (void*) NULL  ,\r
-};\r
-#endif\r
-\r
-void test3a(A3 *list, int number){\r
-       printf("%s %d\n",list->name,number);\r
-}\r
-\r
-static void test31(void)\r
-{\r
-    extern A3 a3[];\r
-    test3a(a3, -1);\r
-}\r
-\r
-#if 0\r
-/* this variation compiles and works with cc65, but gives an error with gcc :=P */\r
-static void test32(void)\r
-{\r
-    extern A3 *a3;\r
-    test3a(a3, -1);\r
-}\r
-#endif\r
-\r
-static void test30(void)\r
-{\r
-    test3a(a3, -1);\r
-}\r
-\r
-/*\r
-  todo: add test on function pointers in the form of (*func)(arg) ...\r
-  cc65 seems to have problems here aswell ;/\r
-*/\r
-\r
-int main(void) {\r
-       test1();\r
-       test2();\r
-       test30();\r
-       test31();\r
-/*     test32(); */\r
-       return 0;\r
-}\r
+/*
+  !!DESCRIPTION!! pointer test
+  !!ORIGIN!!
+  !!LICENCE!!     public domain
+*/
+
+#include "common.h"
+#include <stdio.h>
+
+/*
+  check behaviour on incompletely declared arrays
+*/
+
+char i1[];
+
+void test1(void) {
+int a;
+
+        a=sizeof(i1[0]);
+        printf("%04x - ",a);
+        if(sizeof(i1[0])==sizeof(char)) {
+                /* gcc gives size of element */
+                printf("sizeof(i1[0]) gives size of element\n");
+        }
+        if(sizeof(i1[0])==sizeof(char*)) {
+                printf("sizeof(i1[0]) gives size of pointer to element\n");
+        }
+}
+
+/*
+  check behaviour on string init
+*/
+
+char t1[]="abcde";
+char t2[]={"abcde"};
+
+char *t3="abcde";
+char *t4={"abcde"};
+
+void test2(void) {
+char c1,c2,c3,c4;
+int i,e=0;
+        for(i=0;i<5;i++){
+                c1=t1[i];c2=t2[i];c3=t3[i];c4=t4[i];
+/*              printf("%02x %02x %02x %02x\n",c1,c2,c3,c4); */
+                printf("%c %c %c %c\n",c1,c2,c3,c4);
+                if(!((c1==c2)&(c1==c3)&(c1==c4))) e=1;
+        }
+        if(e) printf("test2 failed.\n");
+        else printf("test2 ok.\n");
+}
+
+/*
+  check behaviour on extern-declarations inside functions
+*/
+
+typedef struct {
+  char *name;
+  void *func;
+} A3;
+
+#ifdef NO_SLOPPY_STRUCT_INIT
+A3 a3[] = {
+  { "test3", (void*) NULL },
+  { "test3", (void*) NULL },
+};
+#else
+/*gcc warning: missing braces around initializer (near initialization for `a3[0]')
+  this type of struct-initialization seems to be kinda common */
+A3 a3[] = {
+    "test3", (void*) NULL  ,
+    "test3", (void*) NULL  ,
+};
+#endif
+
+void test3a(A3 *list, int number){
+        printf("%s %d\n",list->name,number);
+}
+
+static void test31(void)
+{
+    extern A3 a3[];
+    test3a(a3, -1);
+}
+
+#if 0
+/* this variation compiles and works with cc65, but gives an error with gcc :=P */
+static void test32(void)
+{
+    extern A3 *a3;
+    test3a(a3, -1);
+}
+#endif
+
+static void test30(void)
+{
+    test3a(a3, -1);
+}
+
+/*
+  todo: add test on function pointers in the form of (*func)(arg) ...
+  cc65 seems to have problems here aswell ;/
+*/
+
+int main(void) {
+        test1();
+        test2();
+        test30();
+        test31();
+/*      test32(); */
+        return 0;
+}