Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

language semantics shouldn't depend on the compiler #824

Open
andychu opened this issue Sep 3, 2020 · 1 comment
Open

language semantics shouldn't depend on the compiler #824

andychu opened this issue Sep 3, 2020 · 1 comment

Comments

@andychu
Copy link
Contributor

andychu commented Sep 3, 2020

Perl even documents this:

https://perldoc.perl.org/perlnumber.html#Storing-numbers

Perl can internally represent numbers in 3 different ways: as native integers, as native floating point numbers, and as decimal strings. Decimal strings may have an exponential notation part, as in "12.34e-56" . Native here means "a format supported by the C compiler which was used to build perl".

I think integer and floating point semantics are reasonably well defined though?

Issues:

  • Oil uses 32 bit int (even on 64 bit) while other shells use 64 bits (long int)
  • printf had an issue, with negative numbers I think

In theory we want Oil on two different machines to behave the same way, even if they were compiled with a different compiler. It makes things more reproducible

@andychu
Copy link
Contributor Author

andychu commented Sep 24, 2020

Integer overflow is undefined behavior in C.

When undefined behavior is invoked, the behavior depends on the compiler. So we should avoid overflow for user operations.

Instead we can use these compiler extensions:

https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html

https://clang.llvm.org/docs/LanguageExtensions.html


Also TODO:

  • document portability
    • we use the EXTGLOB extension for GNU glob
    • and eventually these overflow builtins
    • otherwise it's ISO C++11 and POSIX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant