Closed AGPX closed 1 month ago
In the following code the sizeof returns 1, but it should returns the size of the array (including the 0 terminator):
sizeof
#include "common.h" static const unsigned char f[] = "\0\377"; static const unsigned char g[] = "\0ÿ"; int main(void) { if (sizeof(f) != 3 || sizeof(g) != 3) abort2("1"); if (f[0] != g[0]) abort2("2"); if (f[1] != g[1]) abort2("3"); if (f[2] != g[2]) abort2("4"); return 0; }
with common.h:
common.h
#pragma once #include <stdio.h> #include <string.h> #define register #define double float #define __attribute__(x) #define __complex__ #define NULL (void *)0 static void abort() { printf("** TEST FAILED **!\n"); } static void abort2(const char *msg) { printf("%s\n", msg); printf("** TEST FAILED **!\n"); }
Fixed, please make sure to save the file as iso-8859 and not UTF-8
Test passed.
In the following code the
sizeof
returns 1, but it should returns the size of the array (including the 0 terminator):with
common.h
: