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

Integer bit sizes are not respected #117

Open
MaddyGuthridge opened this issue Dec 11, 2024 · 3 comments
Open

Integer bit sizes are not respected #117

MaddyGuthridge opened this issue Dec 11, 2024 · 3 comments

Comments

@MaddyGuthridge
Copy link

MaddyGuthridge commented Dec 11, 2024

Consider the following program:

/**
 * Convert a string to I64, finishing when a non-numeric character is
 * encountered.
 */
I64 StrToI64(U8 *str)
{
  I64 total = 0;
  for (I64 i = 0; str[i] >= '0' && str[i] <= '9'; i++)
  {
    total *= 10(I64);
    total += (str[i] - '0')(I64);
    "%u\n", total;
  }
  return total;
}

U0 Main()
{
    "5489811661987 | %u\n",StrToI64("5489811661987");
}

The values appear to be treated as an I32 instead of an I64.

⋙   hcc -o bin/number src/number.hc && ./bin/number
5
54
548
5489
54898
548981
5489811
54898116
548981166
1194844365
3358509067
3520319606
843457699
5489811661987 | 843457699
@MaddyGuthridge
Copy link
Author

MaddyGuthridge commented Dec 11, 2024

Did some fiddling, and the values seem to be correct internally, so it is only when they are printed that it becomes a problem, so my guess is that the format strings need to be fixed.

@Jamesbarford
Copy link
Owner

Ah so the "%<format>\n", <value> under the hood uses C's printf so in your instance above %lld would do the trick. I'm aware this is less than ideal however it was the simplest way to get it working

@MaddyGuthridge
Copy link
Author

Ah in that case, a documentation update would be perfect to resolve this!

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

No branches or pull requests

2 participants