Post Reply 
hpgcc2 loop problem
03-15-2021, 10:14 AM (This post was last modified: 03-15-2021 10:04 PM by brickviking.)
Post: #2
RE: hpgcc2 loop problem
From quick testing here, your C code appears to be mostly correct. As you suspected, you're seeing overflows in your output for certain large inputs.
I can't tell what your HP code is doing though, as I've never tried compiling stuff under hpgcc and executing it from the calculator.

This is the C code I used to test that things work, at least on a Linux machine (and probably a Microsoft setup too):

Code:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
  int n, i;
  /* Need a bigger value for results above 2e9. May not work for hpgcc2, in this case remove unsigned keyword */
  unsigned long long sum=0;
  /* Some arg checking first */
  if (argc < 2) {
    printf("Cannot run with nothing\n");
    exit(1);
  }
  if (argc > 2) {
    printf("Too many args; I only need one number.\n");
    exit(1);
  }
  /* Absolutely no checking that argv[1] is an int */
  n = atoi(argv[1]);
  for (i=1; i<=n; i++) {
    sum += i;
  }
  /* printf need %lld because of the unsigned long long value we're printing
      You're putting value back on the stack, so calculator will deal with printing instead */
  printf("%lld\n", sum);
  exit(0);
}


(Post 336)

Regards, BrickViking
HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
hpgcc2 loop problem - BINUBALL - 03-13-2021, 06:41 AM
RE: hpgcc2 loop problem - brickviking - 03-15-2021 10:14 AM
RE: hpgcc2 loop problem - toml_12953 - 03-15-2021, 10:22 AM
RE: hpgcc2 loop problem - BINUBALL - 03-15-2021, 11:18 AM
RE: hpgcc2 loop problem - Egan Ford - 03-15-2021, 05:55 PM
RE: hpgcc2 loop problem - BINUBALL - 03-16-2021, 12:42 AM
RE: hpgcc2 loop problem - BINUBALL - 03-16-2021, 03:34 AM
RE: hpgcc2 loop problem - Egan Ford - 03-18-2021, 05:01 PM
RE: hpgcc2 loop problem - Claudio L. - 03-16-2021, 04:20 PM
RE: hpgcc2 loop problem - Egan Ford - 03-18-2021, 05:02 PM
RE: hpgcc2 loop problem - Claudio L. - 03-19-2021, 02:51 PM
RE: hpgcc2 loop problem - BINUBALL - 03-20-2021, 07:38 AM
RE: hpgcc2 loop problem - BINUBALL - 03-17-2021, 01:19 AM



User(s) browsing this thread: 1 Guest(s)