Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #92193

Re: sizeof Data types

From Tim Rentsch <txr@alumni.caltech.edu>
Newsgroups comp.lang.c
Subject Re: sizeof Data types
Date 2016-08-12 08:05 -0700
Organization A noiseless patient Spider
Message-ID <kfny442f2od.fsf@x-alumni2.alumni.caltech.edu> (permalink)
References (1 earlier) <chine.bleu-1E482F.20223606082016@news.eternal-september.org> <nod2hs$ubb$1@dont-email.me> <chine.bleu-BEBEE0.12373209082016@news.eternal-september.org> <kfnbn0zgtyc.fsf@x-alumni2.alumni.caltech.edu> <chine.bleu-47B1E9.11110111082016@news.eternal-september.org>

Show all headers | View raw


Siri Cruise <chine.bleu@yahoo.com> writes:

> In article <kfnbn0zgtyc.fsf@x-alumni2.alumni.caltech.edu>,
>  Tim Rentsch <txr@alumni.caltech.edu> wrote:
>
>> The #define's for the case where sizeof_float > sizeof_intptr_t
>> are a bit strange.  They change the types of these functions,
>> and they cause float values to be stored as doubles.  I don't
>> know if this is what you meant or if it happened accidentally
>> as a code saving measure.  From here on I'm assuming it was
>> just an accident (and there are obvious modifications if it
>> was intentional).  This isn't a big deal, I mention it just
>> to be clear that I didn't overlook it.
>
> The only reason I know of to use a single float is to save space.
> When I have to store a value as a pointer to allocated memory,
> I've lost any space savings, so I use the more accurate double.
> My abandonned code that useds vector functions used floats because
> the functions are only defined on float[4].

The point of my comment is not about space but code quality.  As
written in your post the code looks brittle.  Also there seems to
be no point to widening the stored value, since the value to be
stored comes from a 'float' parameter.  Here is an excerpt from
the original long posting:

[..the following from Siri Cruise just slightly upthread..]
> Dictionary *floatplist = ...floatplist_isfloat
>                 ...floatplist_lengthen
>                 ...floatplist_add...;
> Object newfloat (float f) {
>     return putfloatdata((Object){floatplist, 0}, f);
> }
> static bool floatplist_isfloat (Object obj) {return true;}
> static Object floatplist_lengthen (Object obj) {
>     return newdouble(getfloatdata(obj));
> }
> static Object floatplist_add (Object obj, Object arg) {
>     return newfloat(getflaotdata(obj)+ getflaotdata(arg));
> }

Extra precision is stored but then it is thrown away when
newfloat() is called (eg, in floatplist_add()).  That by itself
is enough of a red flag to be called out in a code review.

I'm still wondering what your response is to the more significant
question, about using if() rather than #if, and thus avoiding the
need for the generated header file defining size-related symbols
for use in the preprocessor.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

sizeof Data types Real Troll <real.troll@trolls.com> - 2016-08-05 18:45 -0400
  sizeof Data types jameskuyper@verizon.net - 2016-08-05 17:10 -0700
  Re: sizeof Data types raltbos@xs4all.nl (Richard Bos) - 2016-08-06 10:35 +0000
  Re: sizeof Data types raltbos@xs4all.nl (Richard Bos) - 2016-08-06 10:36 +0000
  Re: sizeof Data types Jean-Marc Bourguet <jm@bourguet.org> - 2016-08-06 22:29 +0200
    Re: sizeof Data types Ken Brody <kenbrody@spamcop.net> - 2016-08-09 12:55 -0400
  Re: sizeof Data types BartC <bc@freeuk.com> - 2016-08-06 21:43 +0100
    Re: sizeof Data types jameskuyper@verizon.net - 2016-08-06 15:25 -0700
      Re: sizeof Data types David Brown <david.brown@hesbynett.no> - 2016-08-08 09:48 +0200
        Re: sizeof Data types James Kuyper <jameskuyper@verizon.net> - 2016-08-08 11:05 -0400
          Re: sizeof Data types David Brown <david.brown@hesbynett.no> - 2016-08-08 17:57 +0200
        Re: sizeof Data types supercat@casperkitty.com - 2016-08-08 08:36 -0700
          Re: sizeof Data types David Brown <david.brown@hesbynett.no> - 2016-08-08 19:05 +0200
            Re: sizeof Data types supercat@casperkitty.com - 2016-08-08 14:09 -0700
              Re: sizeof Data types David Brown <david.brown@hesbynett.no> - 2016-08-09 09:38 +0200
                Re: sizeof Data types Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-09 11:23 +0100
                Re: sizeof Data types Tim Rentsch <txr@alumni.caltech.edu> - 2016-08-12 07:42 -0700
                Re: sizeof Data types Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-12 21:38 +0100
                Re: sizeof Data types Keith Thompson <kst-u@mib.org> - 2016-08-09 08:12 -0700
                Re: sizeof Data types supercat@casperkitty.com - 2016-08-10 10:36 -0700
                Re: sizeof Data types Keith Thompson <kst-u@mib.org> - 2016-08-10 11:42 -0700
      Re: sizeof Data types Philip Lantz <prl@canterey.us> - 2016-08-11 10:20 -0700
        Re: sizeof Data types Keith Thompson <kst-u@mib.org> - 2016-08-11 12:04 -0700
        Re: sizeof Data types Tim Rentsch <txr@alumni.caltech.edu> - 2016-08-12 08:22 -0700
    Re: sizeof Data types Nobody <nobody@nowhere.invalid> - 2016-08-07 01:32 +0100
      Re: sizeof Data types Keith Thompson <kst-u@mib.org> - 2016-08-06 18:10 -0700
  Re: sizeof Data types Siri Cruise <chine.bleu@yahoo.com> - 2016-08-06 20:22 -0700
    Re: sizeof Data types Ian Collins <ian-news@hotmail.com> - 2016-08-07 15:40 +1200
    Re: sizeof Data types Ken Brody <kenbrody@spamcop.net> - 2016-08-09 13:06 -0400
      Re: sizeof Data types Siri Cruise <chine.bleu@yahoo.com> - 2016-08-09 12:37 -0700
        Re: sizeof Data types Tim Rentsch <txr@alumni.caltech.edu> - 2016-08-11 09:18 -0700
          Re: sizeof Data types Siri Cruise <chine.bleu@yahoo.com> - 2016-08-11 11:11 -0700
            Re: sizeof Data types Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2016-08-11 12:26 -0600
              Re: sizeof Data types David Brown <david.brown@hesbynett.no> - 2016-08-11 23:31 +0200
                Re: sizeof Data types supercat@casperkitty.com - 2016-08-11 14:59 -0700
              Re: sizeof Data types Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-08-12 00:15 -0700
            Re: sizeof Data types Tim Rentsch <txr@alumni.caltech.edu> - 2016-08-12 08:05 -0700
  Re: sizeof Data types John Bode <jfbode1029@gmail.com> - 2016-08-08 12:38 -0700
    Re: sizeof Data types Ken Brody <kenbrody@spamcop.net> - 2016-08-09 13:08 -0400
      Re: sizeof Data types Keith Thompson <kst-u@mib.org> - 2016-08-09 10:43 -0700
      Re: sizeof Data types "James R. Kuyper" <jameskuyper@verizon.net> - 2016-08-09 13:41 -0400
        Re: sizeof Data types Ken Brody <kenbrody@spamcop.net> - 2016-08-10 11:51 -0400
          Re: sizeof Data types "James R. Kuyper" <jameskuyper@verizon.net> - 2016-08-10 12:35 -0400
            Re: sizeof Data types Ken Brody <kenbrody@spamcop.net> - 2016-08-11 11:53 -0400
              Re: sizeof Data types "James R. Kuyper" <jameskuyper@verizon.net> - 2016-08-13 11:29 -0400
                Re: sizeof Data types supercat@casperkitty.com - 2016-08-13 09:18 -0700
          Re: sizeof Data types Keith Thompson <kst-u@mib.org> - 2016-08-10 10:13 -0700
            Re: sizeof Data types Ken Brody <kenbrody@spamcop.net> - 2016-08-11 11:56 -0400
  Re: sizeof Data types Ken Brody <kenbrody@spamcop.net> - 2016-08-09 12:59 -0400
    Re: sizeof Data types "James R. Kuyper" <jameskuyper@verizon.net> - 2016-08-09 13:49 -0400
      Re: sizeof Data types Ken Brody <kenbrody@spamcop.net> - 2016-08-10 12:08 -0400
    Re: sizeof Data types Keith Thompson <kst-u@mib.org> - 2016-08-09 11:35 -0700

csiph-web