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


Groups > comp.lang.c > #25928

Re: Limitations and workarounds to expressions defining size of an array

From Eric Sosman <esosman@ieee-dot-org.invalid>
Newsgroups comp.lang.c
Subject Re: Limitations and workarounds to expressions defining size of an array
Date 2012-09-04 18:24 -0400
Organization A noiseless patient Spider
Message-ID <k25v2e$i60$1@dont-email.me> (permalink)
References <504636db$0$1709$426a74cc@news.free.fr> <20120904113418.486@kylheku.com> <k25kmb$fje$1@dont-email.me> <k25qj3$n5k$1@dont-email.me> <504671B5.2080202@verizon.net>

Show all headers | View raw


On 9/4/2012 5:25 PM, James Kuyper wrote:
> On 09/04/2012 05:07 PM, Eric Sosman wrote:
>> On 9/4/2012 3:22 PM, BartC wrote:
>>> "Kaz Kylheku" <kaz@kylheku.com> wrote in message
>>> news:20120904113418.486@kylheku.com...
>>>> On 2012-09-04, Francois Grieu <fgrieu@gmail.com> wrote:
>>>>> Can I
>>>>> - use floating point at all ?
>>>>> - if yes: use sqrt, log, exp ?
>>>>
>>>> No. Constant expressions cannot contain funtion calls.
>>>
>>> Yet, an expression such as sqrt(9.0) seems to be reduced to 3.0 on the
>>> first two compilers I tried.
>>
>>       Don't confuse definition with optimization.  Also, try your
>> compilers on
>>
>> 	strcspn("BartC", "abcdefghijklmnopqrsBCuvwxyz")
>>
>> ... and let us know if they replace it with `3'.
>
> That expression has a value of 0. Were you thinking of strspn()?

     Indeed, I was.  Too much 'c', I guess.  ;-)

> [...] Does your compiler have any problems
> with it?

     BartC reports the compilers he tested implemented `sqrt(9.0)'
as `3.0', implying that the actual function call was not performed
at run-time.  (He presumably used extra-linguistic means to find
this out.)  He went on to suggest that this somehow put `sqrt(9.0)'
on an equal footing with a "constant expression."  My example was
intended to show another function whose value is knowable before
run-time, hence similar to `sqrt(9.0)', but most likely not similarly
optimized.  That is, I was trying to show the fallacy of reasoning
from observed behavior backward to the Standard, instead of from the
Standard forward to required behavior.

     What I showed instead was carelessness, sigh.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid
"The speed at which the system fails is usually not important."

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


Thread

Limitations and workarounds to expressions defining size of an array Francois Grieu <fgrieu@gmail.com> - 2012-09-04 19:14 +0200
  Re: Limitations and workarounds to expressions defining size of an array James Kuyper <jameskuyper@verizon.net> - 2012-09-04 14:08 -0400
    Re: Limitations and workarounds to expressions defining size of an array Francois Grieu <fgrieu@gmail.com> - 2012-09-05 09:56 +0200
      Re: Limitations and workarounds to expressions defining size of an array James Kuyper <jameskuyper@verizon.net> - 2012-09-05 07:33 -0400
        Re: Limitations and workarounds to expressions defining size of an array Francois Grieu <fgrieu@gmail.com> - 2012-09-05 23:39 +0200
          Re: Limitations and workarounds to expressions defining size of an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-05 18:11 -0400
    Re: Limitations and workarounds to expressions defining size of an array James Kuyper <jameskuyper@verizon.net> - 2012-09-05 07:17 -0400
  Re: Limitations and workarounds to expressions defining size of an array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-04 19:18 +0100
  Re: Limitations and workarounds to expressions defining size of an array Kaz Kylheku <kaz@kylheku.com> - 2012-09-04 18:41 +0000
    Re: Limitations and workarounds to expressions defining size of an array "BartC" <bc@freeuk.com> - 2012-09-04 20:22 +0100
      Re: Limitations and workarounds to expressions defining size of an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-04 17:07 -0400
        Re: Limitations and workarounds to expressions defining size of an array James Kuyper <jameskuyper@verizon.net> - 2012-09-04 17:25 -0400
          Re: Limitations and workarounds to expressions defining size of an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-04 18:24 -0400
            Re: Limitations and workarounds to expressions defining size of an array Keith Thompson <kst-u@mib.org> - 2012-09-04 17:29 -0700
        Re: Limitations and workarounds to expressions defining size of an array army1987 <army1987@ask-for-it.invalid> - 2012-09-04 21:26 +0000
          Re: Limitations and workarounds to expressions defining size of an array army1987 <army1987@ask-for-it.invalid> - 2012-09-04 21:31 +0000
            Re: Limitations and workarounds to expressions defining size of an array James Kuyper <jameskuyper@verizon.net> - 2012-09-04 17:41 -0400
              Re: Limitations and workarounds to expressions defining size of an array army1987 <army1987@ask-for-it.invalid> - 2012-09-05 20:45 +0000
                Re: Limitations and workarounds to expressions defining size of an array James Kuyper <jameskuyper@verizon.net> - 2012-09-05 17:23 -0400
                Re: Limitations and workarounds to expressions defining size of an array army1987 <army1987@ask-for-it.invalid> - 2012-09-05 21:30 +0000
                Re: Limitations and workarounds to expressions defining size of an array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-05 23:04 +0100
                Re: Limitations and workarounds to expressions defining size of an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-05 18:17 -0400
                Re: Limitations and workarounds to expressions defining size of an array James Kuyper <jameskuyper@verizon.net> - 2012-09-05 18:29 -0400
            Re: Limitations and workarounds to expressions defining size of an array Kaz Kylheku <kaz@kylheku.com> - 2012-09-04 21:44 +0000
      Re: Limitations and workarounds to expressions defining size of an array Kaz Kylheku <kaz@kylheku.com> - 2012-09-04 21:39 +0000
        Re: Limitations and workarounds to expressions defining size of an array "BartC" <bc@freeuk.com> - 2012-09-04 22:58 +0100
          Re: Limitations and workarounds to expressions defining size of an array Kaz Kylheku <kaz@kylheku.com> - 2012-09-04 22:12 +0000
          Re: Limitations and workarounds to expressions defining size of an array Lowell Gilbert <lgusenet@be-well.ilk.org> - 2012-09-04 18:55 -0400
      Re: Limitations and workarounds to expressions defining size of an array Keith Thompson <kst-u@mib.org> - 2012-09-04 16:51 -0700
        Re: Limitations and workarounds to expressions defining size of an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-04 20:58 -0400
          Re: Limitations and workarounds to expressions defining size of an array Francois Grieu <fgrieu@gmail.com> - 2012-09-05 10:04 +0200
          Re: Limitations and workarounds to expressions defining size of an array Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 04:47 -0700
            Re: Limitations and workarounds to expressions defining size of an array Keith Thompson <kst-u@mib.org> - 2012-09-07 14:04 -0700
              Re: Limitations and workarounds to expressions defining size of an array Casey Carter <casey_at_carter_dot_net@nospam.invalid> - 2012-09-07 16:40 -0500
              Re: Limitations and workarounds to expressions defining size of an array Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 19:54 -0700
                Re: Limitations and workarounds to expressions defining size of an array Keith Thompson <kst-u@mib.org> - 2012-09-08 14:15 -0700
                Re: Limitations and workarounds to expressions defining size of an array lawrence.jones@siemens.com - 2012-09-17 12:09 -0400
        Re: Limitations and workarounds to expressions defining size of an array Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 04:53 -0700
          Re: Limitations and workarounds to expressions defining size of an array "BartC" <bc@freeuk.com> - 2012-09-07 13:07 +0100
            Re: Limitations and workarounds to expressions defining size of an array Keith Thompson <kst-u@mib.org> - 2012-09-07 14:08 -0700
            Re: Limitations and workarounds to expressions defining size of an array Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 19:41 -0700
  Re: Limitations and workarounds to expressions defining size of an array "BartC" <bc@freeuk.com> - 2012-09-04 20:26 +0100
  Re: Limitations and workarounds to expressions defining size of an array Barry Schwarz <schwarzb@dqel.com> - 2012-09-04 14:14 -0700
  Re: Limitations and workarounds to expressions defining size of an array Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 04:41 -0700
  Re: Limitations and workarounds to expressions defining size of an array army1987 <army1987@ask-for-it.invalid> - 2012-09-07 13:32 +0000

csiph-web