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


Groups > comp.lang.forth > #16918

Re: well formed flag ?

From "Rod Pemberton" <do_not_have@notemailnotz.cnm>
Newsgroups comp.lang.forth
Subject Re: well formed flag ?
Date 2012-10-31 20:06 -0400
Organization Aioe.org NNTP Server
Message-ID <k6se6h$g7e$1@speranza.aioe.org> (permalink)
References <2012102715594849117-chrishinsley@gmailcom><k6hsut$8ud$1@speranza.aioe.org> <508d1b70.6381688@192.168.0.50><1538109.deQg0ZcWqx@sunwukong.fritz.box><k6ltvl$gfk$1@speranza.aioe.org><jsSdnfKOD5hcGBPNnZ2dnUVZ8iqdnZ2d@supernews.com><7xwqy9l2qq.fsf@ruckus.brouhaha.com><y8ydnWtcz6zyIRPNnZ2dnUVZ7tGdnZ2d@supernews.com><7xhapcgf8f.fsf@ruckus.brouhaha.com> <k6ri2h$5uv$1@speranza.aioe.org> <7xy5imk3hp.fsf@ruckus.brouhaha.com>

Show all headers | View raw


"Paul Rubin" <no.email@nospam.invalid> wrote in message
news:7xy5imk3hp.fsf@ruckus.brouhaha.com...
> "Rod Pemberton" <do_not_have@notemailnotz.cnm> writes:
...

> > Except for 'restrict' keyword, a pointer may point to or within any C
> > object, i.e., aliased.
>
> I thought the compiler could assume that (e.g.) local variables were
> unaliased, unless the code actually took the address.  E.g., if you say
>
>     int x = 3;
>     foo();
>     print(x);
>
> I have the impression the compiler is allowed to constant-propagate x,
> giving
>
>     foo();
>     print(3);
>
...

> obviously this is not allowed if you do something with &x that might
> change the value of x.

     int x = 3;
     int *y;

     printf("%d\n",x);
     y=&x;
     *y=5;
     printf("%d\n",x);

This prints 3 and 5 here ...  Of course, the contents of 'x' is being
fetched in order to display it, due to the string conversion.  Yes?

Odd ...  I don't know if C can actually print or display a value without
going through a string conversion.  I don't believe that there is a way.  At
the moment, I can't recall any method to do so, if there is ...  I think
that the ability to directly display an integer would be required in order
to do a constant-propagation to a print-like statement that you've
demonstrated.

So, the question becomes how do you detect if a constant has been propagated
or is being fetched for display?  Any internal reference to 'x' in order to
check it's value would be detected by the compiler and might change the code
accordingly.  So, this would require something outside the C context to
modify the contents of the 'x' variable.  Of course, that something needs to
"know" exactly where to store the value.  That leads into the problem of how
do you do know the location without referencing 'x' in a way that the C
compiler or linker can detect the reference, in order to not affect the
outcome ...

> To prevent the propagation from happening (among other uses), the
> "volatile" keyword was introduced.

Well, I'm not familiar with that, or perhaps forgot it ...  A few years
back, I familiarized myself with "restrict".  I know there were some changes
made for implementing "restrict", but I don't recall what they were.  Maybe,
it's related to those changes.  I don't use "restrict", keeping mostly to
ANSI C.

AIUI, the "volatile" keyword is to indicate that a variable's value can be
modified by something outside the C context.  This prevents optimizing away
the read or write of a variables' value from or to memory, e.g., by holding
the value in a register.  E.g., it can be used to ensure reading/writing of
correct values from memory mapped I/O devices, e.g., screen, accessing
values passed from assembly routines, e.g., interrupts, etc.


Rod Pemberton


Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 15:59 +0100
  Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 16:03 +0100
    Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-27 08:33 -0700
      Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-27 09:06 -0700
        Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-27 09:26 -0700
          Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 20:33 +0100
            Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 20:38 +0100
            Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-27 12:52 -0700
              Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 21:01 +0100
                Re: well formed flag ? Coos Haak <chforth@hccnet.nl> - 2012-10-27 22:18 +0200
                Re: well formed flag ? "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2012-10-28 04:19 -0400
        Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 17:44 +0100
          Re: well formed flag ? "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2012-10-27 14:52 -0400
            Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 20:06 +0100
        Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 19:25 +0100
          Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 19:33 +0100
          Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-27 15:08 -0700
            Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-28 00:53 +0100
  Re: well formed flag ? Mark Wills <forthfreak@gmail.com> - 2012-10-27 09:31 -0700
    Re: well formed flag ? "A. K." <akk@nospam.org> - 2012-10-27 19:21 +0200
      Re: well formed flag ? Mark Wills <forthfreak@gmail.com> - 2012-10-27 10:33 -0700
        Re: well formed flag ? Coos Haak <chforth@hccnet.nl> - 2012-10-27 22:21 +0200
        Re: well formed flag ? "Ed" <invalid@nospam.com> - 2012-10-28 12:33 +1100
          Re: well formed flag ? "Elizabeth D. Rather" <erather@forth.com> - 2012-10-27 15:46 -1000
  Re: well formed flag ? "Elizabeth D. Rather" <erather@forth.com> - 2012-10-27 08:54 -1000
    Re: well formed flag ? Chris Hinsley <chris.hinsley@gmail.com> - 2012-10-27 20:11 +0100
  Re: well formed flag ? "Ed" <invalid@nospam.com> - 2012-10-28 11:05 +1100
    Re: well formed flag ? stephenXXX@mpeforth.com (Stephen Pelc) - 2012-10-28 11:53 +0000
      Re: well formed flag ? Bernd Paysan <bernd.paysan@gmx.de> - 2012-10-28 14:17 +0100
        Re: well formed flag ? mhx@iae.nl (Marcel Hendrix) - 2012-10-28 16:59 +0200
          Re: well formed flag ? Bernd Paysan <bernd.paysan@gmx.de> - 2012-10-28 18:37 +0100
        Re: well formed flag ? "Ed" <invalid@nospam.com> - 2012-10-29 23:46 +1100
          Re: well formed flag ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-10-29 08:33 -0500
            Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-10-29 08:25 -0700
              Re: well formed flag ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-10-29 12:27 -0500
                Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-10-30 08:18 -0700
                Re: well formed flag ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-10-30 10:33 -0500
                Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-10-30 08:48 -0700
                Re: well formed flag ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-10-30 11:45 -0500
                Re: well formed flag ? Bernd Paysan <bernd.paysan@gmx.de> - 2012-10-30 20:10 +0100
                Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-10-30 15:10 -0700
                Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-10-30 18:28 -0700
                Re: well formed flag ? Alex McDonald <blog@rivadpm.com> - 2012-11-02 05:28 -0700
                Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-11-02 08:13 -0700
                Re: well formed flag ? "Elizabeth D. Rather" <erather@forth.com> - 2012-10-30 12:50 -1000
                Re: well formed flag ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-31 14:57 +0000
                Re: well formed flag ? Bernd Paysan <bernd.paysan@gmx.de> - 2012-10-31 17:58 +0100
                Re: well formed flag ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-31 17:39 +0000
                Re: well formed flag ? David Thompson <dave.thompson2@verizon.net> - 2012-11-16 23:21 -0500
                Aliasing (was: well formed flag ?) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-31 14:03 +0000
                Re: well formed flag ? "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2012-10-31 12:06 -0400
                Re: well formed flag ? Paul Rubin <no.email@nospam.invalid> - 2012-10-31 09:31 -0700
                Aliases (was: well formed flag ?) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-31 17:02 +0000
                Re: well formed flag ? "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2012-10-31 20:06 -0400
      Re: well formed flag ? "Ed" <invalid@nospam.com> - 2012-10-29 23:47 +1100
        Re: well formed flag ? stephenXXX@mpeforth.com (Stephen Pelc) - 2012-10-30 18:02 +0000
          Re: well formed flag ? "Ed" <invalid@nospam.com> - 2012-10-31 11:44 +1100
            Re: well formed flag ? stephenXXX@mpeforth.com (Stephen Pelc) - 2012-10-31 09:25 +0000

csiph-web