-
|
Can you explain what the S32FromZ and S32FromZInternal funcs are doing in the C implementation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Yeah, these functions parse a 32-bit signed integer from a C-string. Anyways, user code should simply call S32FromZ(). In that function, it makes a copy of the string argument passed in. It passes this onto the internal version, it passes in the copy of the string argument by reference, this is mainly done so that the c-string is 'advanced' past whatever digit was parsed. This doesn't really mean much except that it could be inspected during debugging or the caller could inspect the string that it passed in and the result of that string. It parses the int by looping only as long as it is reading an ascii value between the char values for 0 through 9. When it's parsing an int, it multiplies the result by 10 (to add a digit to the final number). It then subtracts the ASCII value of the currently parsed character digit by the char value of 0. That essentially strips the ASCII code out of the digit and gets the effective distance from 0 to get the identity of that number in its pure numerical form (we have converted the char number to its actual numerical digit value). |
Beta Was this translation helpful? Give feedback.
Yeah, these functions parse a 32-bit signed integer from a C-string.
The S32FromZ() is the more friendlier and easy to use version which, just calls the internal version to do the real work.
There is actually a problem with this function. It parses a 32-bit int but it cannot handle the sign of the number. It also does not handle overflow cases.
Anyways, user code should simply call S32FromZ(). In that function, it makes a copy of the string argument passed in. It passes this onto the internal version, it passes in the copy of the string argument by reference, this is mainly done so that the c-string is 'advanced' past whatever digit was parsed. This doesn't really mean much except that it…