News for hackers. Stuff that matters.
Re:Free Pascal by hiker on Sunday December 13, 2020 @12:53PM (#25408446)
Maybe

  int getint(const char **s) {
    int res = 0;
    for (; **s && isspace(**s); (*s)++);
    for (; **s && isdigit(**s); (*s)++)
      res = 10 * res + **s - '0';
    return res;
  }
Re:Free Pascal by mikewarot on Sunday December 13, 2020 @01:20PM (#25408714)
Here's the same code in pascal.

    function getnum(var s : string):integer;
    var
      c : char;
      value : integer;
    begin
      value := 0;
      while (length(s) <> 0) and NOT(s[1] in ['0'..'9']) do
        delete(s,1,1);
      while (length(s) <> 0) and (s[1] in ['0'..'9']) do
      begin
        value := value * 10 + (ord(s[1])-ord('0'));
        delete(s,1,1);
      end;
      getnum := value;
    end;
Re:Free Pascal by benibela on Sunday December 13, 2020 @01:26PM (#25408781)
And that would be faster than the Pascal version

But it is unsafe. Someone might mistype * * s as *s and then bad things happen.

Pascal strings are basically memory safe. With range checking enabled, you can write whatever and it can only access characters in the string.

Ofc, then people disable the range checking in release builds to make it faster