jyn514 / saltwater

A C compiler written in Rust, with a focus on good error messages.
BSD 3-Clause "New" or "Revised" License
294 stars 27 forks source link

Hexadecimal floating constant requires an exponent #483

Closed hdamron17 closed 4 years ago

hdamron17 commented 4 years ago

According to the grammar in 6.4.4.2, hexadecimal floating constants require a binary exponent (p). A binary exponent of 0 is used to bypass this restriction. Not sure if it's anything we should worry about because we are less restrictive than the C standard.

Code Example

int printf(const char *format, ...);
int main() {
  printf("%f\n", (0x1.5));
}

Expected Compilation Error (clang)

test.c:3:24: error: hexadecimal floating constant requires an exponent
  printf("%f\n", (0x1.5));
                       ^
1 error generated.

Actual Behavior: no error with output

1.312500
jyn514 commented 4 years ago

This is known and expected behavior, see https://docs.rs/hexponent/0.3.1/hexponent/#differences-from-the-specification. Where do you think would be a good place to document this?

hdamron17 commented 4 years ago

Ah, you could mention it in you IMPLEMENTATION_DEFINED.md section. Or it's probably fine to just leave it off- I just noticed this as I was exploring parse_num for the big migration (and I doubt most users will be digging that deep).

jyn514 commented 4 years ago

I don't expect most people to read through IMPLEMENTATION_DEFINED.md anyway so I can put it in there.