lacc icon indicating copy to clipboard operation
lacc copied to clipboard

Size of standard types

Open cesss opened this issue 4 years ago • 2 comments

I see that typetree.c hardcodes the size of standard types (char, short, int, float, etc...) to those of the typical x86_64 platforms... I feel this can be a cause for issues on some platforms if for some reason the host compiler has a different size for some of these types (which I guess can happen even if it's x86_64, because I don't think it's forbidden for a compiler to take, let's say, 4 bytes for short ints if it wishes to do so).

So, I believe lacc should have its own limits.h in the include/stdlib folder, because AFAIK the sizes of these types is compiler-specific rather than OS-specific.

Also, I suggest to list the sizes of these standard types at the toplevel readme.

cesss avatar Jan 17 '21 14:01 cesss

By the way, if I'd like to change the sizes of the standard types (obviously for using lacc in AST mode only, because generating assembly would require writing a new backend), is typetree.c the only place where I need to set the type sizes, or should I modify other files too?

cesss avatar Jan 17 '21 14:01 cesss

Regarding different type sizes, I think the correct way to look at this is to do a mapping closer to the front-end. If for example we want to have sizeof(long) = 4 instead of 8, then "long" should not map to T_LONG in lacc, but rather T_INT. I have thought about this, and for platform compatibility (for ex with windows) it is definitely something I want to look at at some point.

larmel avatar Jan 31 '21 21:01 larmel