-
Notifications
You must be signed in to change notification settings - Fork 143
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Description
shecc currently only supports int
and char
integer types. Adding support for short
and long
would improve C99 compliance and enable compilation of more real-world C code.
Current Behavior
short s = 32767; // Error: "invalid type specifier"
long l = 2147483647; // Error: "invalid type specifier"
unsigned short us; // Error: not supported
Expected Behavior
Support standard C integer type hierarchy:
short
/short int
(typically 16-bit)long
/long int
(32-bit or 64-bit)long long
/long long int
(at least 64-bit)- Combined with
unsigned
modifier
Implementation Requirements
1. Lexer Changes
- Recognize
short
andlong
keywords - Handle type specifier combinations (
short int
,long int
, etc.)
2. Type System
- Add new base types to enum
- Define size constants for each type
- Handle type promotion rules
3. Code Generation
- Proper sign/zero extension for different sizes
- Correct load/store instructions for each size
- Type casting between different integer sizes
Test Cases
// Basic declarations
short s1 = 100;
long l1 = 1000000;
long long ll1 = 1000000000000LL;
// Type promotion
int i = s1; // short to int
long l = i; // int to long
short s2 = (short)l1; // explicit cast
// Arithmetic
short result = s1 + 10;
long product = l1 * 2;
// Arrays and pointers
short arr[10];
long *ptr = &l1;
Benefits
- Better C99 standard compliance
- Support for more existing C code
- Proper handling of different data sizes
- Foundation for full integer type system
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request