[Cfp-interest 1730] Re: AI about macro for array size in example

Jim Thomas jaswthomas at sbcglobal.net
Tue Jul 28 10:57:13 PDT 2020


I’ve used the LEN+1 style in code too. But don’t see it anywhere in the C examples. I’m inclined to stay with my last suggestion, with #define MAXSIZE 41. The text below the code acknowledges the NULL character in the determination of the size 41.

- Jim Thomas

> On Jul 26, 2020, at 9:49 AM, Mike Cowlishaw <mfc at speleotrove.com> wrote:
> 
> Yes, tricky.   STRLEN is one less that the needed constant, too.   In fact, in my code, I actually use:
>   
>   #define INTLEN 11           // length needed for an ASCII'd Int   
>                               // this is from a shared .h; Int is 32-bit int .. I never
>                               // never use raw 'int' in my code and in fact in that .h have:  
>                               //   #define Int int32_t
>                               //   #define int ?
>                               // to ensure that I don't [I still have a lot of 8-bit and 16-bit
>                               // code/platforms to test on]
>  
>   // then ...
>   char buffer[INTLEN+1];      // i.e., the space for the null char is added here so is explicit
>  
> So, perhaps
>  
>    #define MAXHEXCHARS 40
>      ...
>    char s[MAXHEXCHARS+1];
>  
> ... but maybe we're spending too much time on this :-).  Your call.
>  
>  
> 
>> From: Jim Thomas [mailto:jaswthomas at sbcglobal.net] 
>> Sent: 25 July 2020 23:18
>> To: Mike Cowlishaw
>> Cc: CFP
>> Subject: Re: [Cfp-interest 1718] AI about macro for array size in example
>> 
>> I’d like to avoid alluding to the size of a string. It’s really a size greater than the lengths of the hex strings, which is what is needed for the array size. The C standard uses “maxsize” for parameters with this meaning. How about 
>> 
>> #define MAXSIZE 41 
>>   // > intermediate hex string length
>> 
>> - Jim Thomas
>> 
>>> On Jul 24, 2020, at 6:36 AM, Mike Cowlishaw <mfc at speleotrove.com <mailto:mfc at speleotrove.com>> wrote:
>>> 
>>> Looks good.   Maybe MAXSTRSIZE?  (S on its own is a bit mysterious, and it's not clear how to pronounce it).
>>>  
>>> Mike
>>> 
>>>> From: Cfp-interest [mailto:cfp-interest-bounces at oakapple.net <mailto:cfp-interest-bounces at oakapple.net>] On Behalf Of Jim Thomas
>>>> Sent: 24 July 2020 00:33
>>>> To: CFP
>>>> Subject: [Cfp-interest 1718] AI about macro for array size in example
>>>> 
>>>> Action item:
>>>>>     Jim: For cfp3x-annex-20200706.pdf, Annex X, new example (page 33), change the magic number 40 (which needs to be verified) to be a macro and add in a descriptive definition of that macro.
>>>> 
>>>> Oops. 41 instead of 40. How does the following look?
>>>> 
>>>> - Jim Thomas
>>>> 
>>>> +++++++++++++++++++++++++++
>>>> [4] EXAMPLE    If the IEC 60559 binary128 format is supported as a non-arithmetic format, data in binary128 format can be converted to type _Decimal128 as follows:
>>>> #define __STDC_WANT_IEC_60559_TYPES_EXT__
>>>> #include <stdlib.h>
>>>> #define MAXSSIZE 41     // of intermediate hexadecimal string 
>>>> unsigned char b128[16]; // for input binary128 datum
>>>> _Decimal128 d128;       // for result
>>>> char s[MAXSSIZE];
>>>> // store input binary128 datum in array b128
>>>> ...
>>>> strfromencf128(s, MAXSSIZE, “%a”, b128);
>>>> d128 = strtod128(s, NULL);
>>>> ...
>>>> Use of “%a” for formatting assures an exact conversion of the value in binary format to character sequence. The value of that character sequence will be correctly rounded to _Decimal128, as specified above in this subclause. The array s for the output of strfromencf128 need have no greater size than 41, which is the maximum length of strings of the form
>>>> 
>>>> [-]0xh.h…hp±d, where there are up to 29 hexadecimal digits h and d has 5 digits
>>>> 
>>>> plus 1 for the null character.
>>>> 
>>>> +++++++++++++++++++++++++++
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20200728/5cf9ffb6/attachment-0001.htm>


More information about the Cfp-interest mailing list