drmortalwombat / oscar64

Optimizing Small memory C Compiler Assembler and Runtime for C64
GNU General Public License v3.0
273 stars 24 forks source link

Wrong sizeof calculation #106

Closed AGPX closed 1 month ago

AGPX commented 1 month ago

In the following code the sizeof returns 1, but it should returns the size of the array (including the 0 terminator):

#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:

#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");
}
drmortalwombat commented 1 month ago

Fixed, please make sure to save the file as iso-8859 and not UTF-8

AGPX commented 1 month ago

Test passed.