At http://www.lysator.liu.se/c/dmr-on-noalias.html
Dennis Ritchie strongly denounces some noalias
qualifier which was proposed for addition to the language
at some point. Can someone give me some historical
background and what it was supposed to do ? Was it
like restricted pointers ? 21 6945
Spiros Bousbouras <sp****@gmail.comwrites:
At http://www.lysator.liu.se/c/dmr-on-noalias.html
Dennis Ritchie strongly denounces some noalias
qualifier which was proposed for addition to the language
at some point. Can someone give me some historical
background and what it was supposed to do ? Was it
like restricted pointers ?
A Google search for "c noalias" turned up this page: http://www.quut.com/c/noalias-88.html
The page didn't load for me immediately, but it's in Google's
cache.
--
"All code should be deliberately written for the purposes of instruction.
If your code isn't readable, it isn't finished yet."
--Richard Heathfield
On Sep 7, 3:33 pm, Spiros Bousbouras <spi...@gmail.comwrote:
Athttp://www.lysator.liu.se/c/dmr-on-noalias.html
Dennis Ritchie strongly denounces some noalias
qualifier which was proposed for addition to the language
at some point. Can someone give me some historical
background and what it was supposed to do ? Was it
like restricted pointers ?
"noalias" was an early proposal to handle aliasing/non-aliasing
problems in the C language. That proposal turned out to be completely
broken, as Dennis Ritchie and probably some others recognised. This
was then replaced with "restrict" pointers which is a sane solution to
the problem.
christian.bau wrote:
>"noalias" was an early proposal to handle aliasing/non-aliasing problems in the C language. That proposal turned out to be completely broken, as Dennis Ritchie and probably some others recognised. This was then replaced with "restrict" pointers which is a sane solution to the problem.
It didn't exactly go away:
C166 user's Guide: NOALIAS Compiler Directive
[ http://www.keil.com/support/man/docs...66_noalias.htm ]
GCC Options for Code Generation:
-falias-check
-fargument-alias
-fargument-noalias
-fno-argument-noalias-global
[ http://www.delorie.com/gnu/docs/gcc/gcc_13.html ]
On Sep 8, 1:19 pm, Guy Macon <http://www.guymacon.com/wrote:
christian.bau wrote:
"noalias" was an early proposal to handle aliasing/non-aliasing
problems in the C language. That proposal turned out to be completely
broken, as Dennis Ritchie and probably some others recognised. This
was then replaced with "restrict" pointers which is a sane solution to
the problem.
It didn't exactly go away:
C166 user's Guide: NOALIAS Compiler Directive
[http://www.keil.com/support/man/docs...6_noalias.htm]
GCC Options for Code Generation:
-falias-check
-fargument-alias
-fargument-noalias
-fno-argument-noalias-global
[http://www.delorie.com/gnu/docs/gcc/gcc_13.html]
You misunderstood. It is quite reasonable and useful to be able to
tell a compiler that certain pointers cannot point to the same object,
so that it can assume that modifying what one pointer points to
doesn't change the value that another pointer points to. _How_ exactly
this is done is critical. I am quite sure that what these gcc options
do is reasonable. Same with C99 "restrict" pointers; they may be a bit
hard to understand but in the end they work in a sensible way. The
"noalias" proposal for the C language and its consequences for the
language were - after closer examination - just insane.
"christian.bau" <ch***********@cbau.wanadoo.co.ukwrote in message
news:11*********************@k79g2000hse.googlegro ups.com...
The
"noalias" proposal for the C language and its consequences for the
language were - after closer examination - just insane.
The problem was that everything touched by "noalias" becomes "noalias". In
the end it would have clogged up the language horribly, worse than const,
because const propagates only one const to subroutines, whilst "noalias"
propagates two or more "no aliases" to the caller.
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm
Malcolm McLean wrote:
"christian.bau" <ch***********@cbau.wanadoo.co.ukwrote in message
>The "noalias" proposal for the C language and its consequences for the language were - after closer examination - just insane.
The problem was that everything touched by "noalias" becomes
"noalias". In the end it would have clogged up the language
horribly, worse than const, because const propagates only one
const to subroutines, whilst "noalias" propagates two or more "no
aliases" to the caller.
I see no way that 'const' propagates to functions. If a pointer to
a const object is passed to a function, that parameter must be
_declared_ as const, or there is an error. This is simply type
matching. If that const object is passed, by value, to a function,
there is no problem, because the function receives a copy, which is
not const.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
"CBFalconer" <cb********@yahoo.comwrote in message
news:46***************@yahoo.com...
Malcolm McLean wrote:
>"christian.bau" <ch***********@cbau.wanadoo.co.ukwrote in message
>>The "noalias" proposal for the C language and its consequences for the language were - after closer examination - just insane.
The problem was that everything touched by "noalias" becomes "noalias". In the end it would have clogged up the language horribly, worse than const, because const propagates only one const to subroutines, whilst "noalias" propagates two or more "no aliases" to the caller.
I see no way that 'const' propagates to functions. If a pointer to
a const object is passed to a function, that parameter must be
_declared_ as const, or there is an error. This is simply type
matching. If that const object is passed, by value, to a function,
there is no problem, because the function receives a copy, which is
not const.
void foo(const char *str)
{
bar(str);
}
void bar( /* must be const*/ const char *str)
{
}
However
void baz()
{
char *input = malloc(100);
strcpy(input, "Ba ba black sheep");
/* this is OK */
foo(input);
}
const propagates down, but not up, unless it is in the return type.
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm
I just wanna ask if I have a decent understanding of how restrict
pointers work. Here's an example of a function:
void Func(int *p) /* const I'd usually add has been removed for
simplicity */
{
*p += 7;
*p += 7;
}
Assuming this function is outline (i.e. as opposed to inline), then it
CANNOT be optimised to "+= 14" because the function is not free to
assume that what 'p' points to doesn't get changed in the meantime.
That right?
And IF it were written as: void Func(int *restrict p), then it WOULD
be able to perform such an optimisation? That right?
Martin
Martin Wells <wa****@eircom.netwrites:
I just wanna ask if I have a decent understanding of how restrict
pointers work. Here's an example of a function:
void Func(int *p) /* const I'd usually add has been removed for
simplicity */
{
*p += 7;
*p += 7;
}
Assuming this function is outline (i.e. as opposed to inline), then it
CANNOT be optimised to "+= 14" because the function is not free to
assume that what 'p' points to doesn't get changed in the meantime.
That right?
And IF it were written as: void Func(int *restrict p), then it WOULD
be able to perform such an optimisation? That right?
Yes.
Martin Wells wrote:
>
I just wanna ask if I have a decent understanding of how restrict
pointers work. Here's an example of a function:
void Func(int *p) /* const I'd usually add has been removed for
simplicity */
{
*p += 7;
*p += 7;
}
Assuming this function is outline (i.e. as opposed to inline), then it
CANNOT be optimised to "+= 14" because the function is not free to
assume that what 'p' points to doesn't get changed in the meantime.
That right?
And IF it were written as: void Func(int *restrict p), then it WOULD
be able to perform such an optimisation? That right?
That's not what restrict is all about.
Take a look at the C99 prototypes for memcpy and memmove:
void * memcpy(void * restrict s1, const void * restrict s2, size_t n);
void *memmove(void * s1, const void * s2, size_t n);
"restrict" means that all accesses to the object pointed to by s1,
will be made by pointers which were derived from s1.
In this version of memcpy:
void *memcpy(void *restrict s1, const void *restrict s2, size_t n)
{
unsigned char *p1 = s1;
const unsigned char *p2 = s2;
while (n-- != 0) {
*p1++ = *p2++;
}
return s1;
}
all accesses to the object pointed to by s1,
are made through various values of p1, but p1 is derived from s1.
In memmove, because the objects may overlap,
It's possible that s1 and/or pointers derived from s1,
may point to the same addresses
as pointed to by s2 and/or pointers derived from s2.
--
pete
Martin Wells <wa****@eircom.netwrites:
I just wanna ask if I have a decent understanding of how restrict
pointers work. Here's an example of a function:
void Func(int *p) /* const I'd usually add has been removed for
simplicity */
{
*p += 7;
*p += 7;
}
Assuming this function is outline (i.e. as opposed to inline), then it
CANNOT be optimised to "+= 14" because the function is not free to
assume that what 'p' points to doesn't get changed in the meantime.
That right?
And IF it were written as: void Func(int *restrict p), then it WOULD
be able to perform such an optimisation? That right?
I don't think so. In the absence of a 'volatile' keyword, nothing can
happen between the two statements that would affect the value of
either 'p' or '*p'.
I think this is a better example of what you're looking for:
void Func(int *restrict p, int *restrict q)
{
*p += 7;
*q = 0;
*p += 7;
}
The 'restrict' keywords allow the compiler to assume that p and q do
*not* point to the same object, so it can optimize the code to the
equivalent of
*p += 14;
*q = 42;
(I'm too lazy to figure out whether both 'restrict' keywords are
necessary.)
Note that if you do something like this:
int x = 0;
Func(&x, &x);
you've invoked undefined behavior, and the compiler isn't obligated to
diagnose the error (though it can do so if it's sufficiently
clever).
Without the 'restrict' keywords, the compiler isn't allowed to make
this assumption; it has to assume that p and q *might* point to the
same object, and 'Func(&x, &x)' is no longer UB.
I'm not 100% certain about all this, so please take it with a grain of
salt until somebody confirms it.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Richard wrote, On 10/09/07 23:46:
Martin Wells <wa****@eircom.netwrites:
>I just wanna ask if I have a decent understanding of how restrict pointers work. Here's an example of a function:
void Func(int *p) /* const I'd usually add has been removed for simplicity */ { *p += 7;
*p += 7; }
Assuming this function is outline (i.e. as opposed to inline), then it CANNOT be optimised to "+= 14" because the function is not free to assume that what 'p' points to doesn't get changed in the meantime. That right?
And IF it were written as: void Func(int *restrict p), then it WOULD be able to perform such an optimisation? That right?
Yes.
Are you sure? I would have said it could perform the optimisation
without the restrict qualification since there is no intervening code
that could have any effect on *p. Maybe you were thinking of volatile
which would have prevented the optimisation?
--
Flash Gordon
On Sep 11, 12:19 am, pete <pfil...@mindspring.comwrote:
Martin Wells wrote:
I just wanna ask if I have a decent understanding of how restrict
pointers work. Here's an example of a function:
void Func(int *p) /* const I'd usually add has been removed for
simplicity */
{
*p += 7;
*p += 7;
}
Assuming this function is outline (i.e. as opposed to inline), then it
CANNOT be optimised to "+= 14" because the function is not free to
assume that what 'p' points to doesn't get changed in the meantime.
That right?
And IF it were written as: void Func(int *restrict p), then it WOULD
be able to perform such an optimisation? That right?
That's not what restrict is all about.
Take a look at the C99 prototypes for memcpy and memmove:
void * memcpy(void * restrict s1, const void * restrict s2, size_t n);
void *memmove(void * s1, const void * s2, size_t n);
"restrict" means that all accesses to the object pointed to by s1,
will be made by pointers which were derived from s1.
In this version of memcpy:
void *memcpy(void *restrict s1, const void *restrict s2, size_t n)
{
unsigned char *p1 = s1;
const unsigned char *p2 = s2;
while (n-- != 0) {
*p1++ = *p2++;
}
return s1;
}
all accesses to the object pointed to by s1,
are made through various values of p1, but p1 is derived from s1.
In memmove, because the objects may overlap,
It's possible that s1 and/or pointers derived from s1,
may point to the same addresses
as pointed to by s2 and/or pointers derived from s2.
Wow, what a pig's breakfast! I also find "restrict" is often a useful
name for a variable - one more reason to stick with C90!
>
--
pete
Fr************@googlemail.com writes:
[...]
Wow, what a pig's breakfast! I also find "restrict" is often a useful
name for a variable - one more reason to stick with C90!
By doing so, you also restrict (ahem) anyone trying to compile your
code to using C90 compilers.
If you want to avoid C99, I recomend programming in the intersection
of C90 and C99. That mostly means avoiding the new keywords and
implicit int.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Malcolm McLean wrote:
"CBFalconer" <cb********@yahoo.comwrote in message
>Malcolm McLean wrote:
>>"christian.bau" <ch***********@cbau.wanadoo.co.ukwrote in message
The "noalias" proposal for the C language and its consequences for the language were - after closer examination - just insane.
The problem was that everything touched by "noalias" becomes "noalias". In the end it would have clogged up the language horribly, worse than const, because const propagates only one const to subroutines, whilst "noalias" propagates two or more "no aliases" to the caller.
I see no way that 'const' propagates to functions. If a pointer to a const object is passed to a function, that parameter must be _declared_ as const, or there is an error. This is simply type matching. If that const object is passed, by value, to a function, there is no problem, because the function receives a copy, which is not const.
void foo(const char *str) {
bar(str);
}
void bar( /* must be const*/ const char *str) {
}
However
void baz() {
char *input = malloc(100);
strcpy(input, "Ba ba black sheep");
/* this is OK */
foo(input);
}
const propagates down, but not up, unless it is in the return type.
This isn't 'propagation', just insistance on proper type matching,
and preventing writing on a read-only object. Things are much
clearer if you define functions before they are called, which
avoids most prototypes, except for external functions and recursive
groups.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
Martin Wells wrote:
>
I just wanna ask if I have a decent understanding of how restrict
pointers work. Here's an example of a function:
void Func(int *p) {
*p += 7;
*p += 7;
}
Assuming this function is outline (i.e. as opposed to inline), then
it CANNOT be optimised to "+= 14" because the function is not free
to assume that what 'p' points to doesn't get changed in the
meantime. That right?
And IF it were written as: void Func(int *restrict p), then it WOULD
be able to perform such an optimisation? That right?
No, no, no.
void foo(int *p, int *q) {
if (8 == (*p += 3)) {
*q++;
/* now you can no longer assume p to be 8 */
/* because p and q have no 'restrict' */
}
}
(the call that shows this)
int a[22];
...
foo(a+4, a);
or something like that. The restrict is not on the function, but
on the caller, who must ensure the arguments are independant.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
On Sep 7, 7:43 am, "christian.bau" <christian....@cbau.wanadoo.co.uk>
wrote:
"noalias" was an early proposal to handle
aliasing/non-aliasing problems in the C language.
That proposal turned out to be completely
broken, as Dennis Ritchie ... recognised.
Here's the relevant Dennis Ritchie Usenet post:
//groups.google.com/group/comp.lang.c/msg/991b9116ffa83c60?
dmode=source
Although Dennis obviously disapproved of
"broken" proposals, his comment goes further:
Let me begin by saying that I'm not convinced
that even the pre-December qualifiers (`const'
and `volatile') carry their weight; I suspect
that what they add to the cost of learning
and using the language is not repaid in
greater expressiveness.
Dennis' comment seems like a good antidote
to the frequently-heard assumption that
adding a feature to a language automatically
makes it better.
James Dow Allen Fr************@googlemail.com wrote:
On Sep 11, 12:19 am, pete <pfil...@mindspring.comwrote:
That's not what restrict is all about.
Take a look at the C99 prototypes for memcpy and memmove:
void * memcpy(void * restrict s1, const void * restrict s2, size_t n);
void *memmove(void * s1, const void * s2, size_t n);
"restrict" means that all accesses to the object pointed to by s1,
will be made by pointers which were derived from s1.
In this version of memcpy:
void *memcpy(void *restrict s1, const void *restrict s2, size_t n)
{
unsigned char *p1 = s1;
const unsigned char *p2 = s2;
while (n-- != 0) {
*p1++ = *p2++;
}
return s1;
}
all accesses to the object pointed to by s1,
are made through various values of p1, but p1 is derived from s1.
In memmove, because the objects may overlap,
It's possible that s1 and/or pointers derived from s1,
may point to the same addresses
as pointed to by s2 and/or pointers derived from s2.
Wow, what a pig's breakfast!
Why a pig's breakfast? This allows restrict to specify exactly what was
written in words in the previous Standard: that the two pointers to
memcpy() must not point to overlapping areas, and that those to
memmove() may. This is actually the most useful application of restrict
I've found in the Standard.
Richard
"James Dow Allen" <jd*********@yahoo.comwrote in message
news:11**********************@w3g2000hsg.googlegro ups.com...
On Sep 7, 7:43 am, "christian.bau" <christian....@cbau.wanadoo.co.uk>
wrote:
>"noalias" was an early proposal to handle aliasing/non-aliasing problems in the C language. That proposal turned out to be completely broken, as Dennis Ritchie ... recognised.
Here's the relevant Dennis Ritchie Usenet post:
//groups.google.com/group/comp.lang.c/msg/991b9116ffa83c60?
dmode=source
Although Dennis obviously disapproved of
"broken" proposals, his comment goes further:
>Let me begin by saying that I'm not convinced that even the pre-December qualifiers (`const' and `volatile') carry their weight; I suspect that what they add to the cost of learning and using the language is not repaid in greater expressiveness.
Dennis' comment seems like a good antidote
to the frequently-heard assumption that
adding a feature to a language automatically
makes it better.
Mr Ritchie has desinged a successful language whilst the committees has
proposed an unsuccessful standard, so I've give his opinion more weight.
const would have been a good idea, had it been designed in right from the
start of the language. However it doesn't fit C as she is spoke. C++ has
even added a "mutable" keyword. All problems can be solved by adding another
layer of indirection.
On "volatile" I think he is wrong. It doesn't have a place in programs
written in pure C, of course. However I cannot think of any better solution
to the problems of threads and interrupt routines.
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm
<Fr************@googlemail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
On Sep 11, 12:19 am, pete <pfil...@mindspring.comwrote:
>Martin Wells wrote:
I just wanna ask if I have a decent understanding of how restrict
pointers work. Here's an example of a function:
void Func(int *p) /* const I'd usually add has been removed for
simplicity */
{
*p += 7;
*p += 7;
}
Assuming this function is outline (i.e. as opposed to inline), then it
CANNOT be optimised to "+= 14" because the function is not free to
assume that what 'p' points to doesn't get changed in the meantime.
That right?
And IF it were written as: void Func(int *restrict p), then it WOULD
be able to perform such an optimisation? That right?
That's not what restrict is all about. Take a look at the C99 prototypes for memcpy and memmove:
void * memcpy(void * restrict s1, const void * restrict s2, size_t n); void *memmove(void * s1, const void * s2, size_t n);
"restrict" means that all accesses to the object pointed to by s1, will be made by pointers which were derived from s1.
In this version of memcpy:
void *memcpy(void *restrict s1, const void *restrict s2, size_t n) { unsigned char *p1 = s1; const unsigned char *p2 = s2;
while (n-- != 0) { *p1++ = *p2++; } return s1;
}
all accesses to the object pointed to by s1, are made through various values of p1, but p1 is derived from s1.
In memmove, because the objects may overlap, It's possible that s1 and/or pointers derived from s1, may point to the same addresses as pointed to by s2 and/or pointers derived from s2.
Wow, what a pig's breakfast! I also find "restrict" is often a useful
name for a variable - one more reason to stick with C90!
I propose a new syntax
)ptr(
a restricted pointer.
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Vladimir Grul |
last post by:
Hello,
I have a class member function declared as
class some_class {
....
virtual int call(void);
};
Can I use this-> inside the function body?
|
by: Oliver Brausch |
last post by:
Hello,
have you ever heard about this MS-visual c compiler bug?
look at the small prog:
static int x=0;
int bit32() {
return ++x;
}
|
by: Madhur |
last post by:
Hello
what about this nice way to open a file in single line rather than using
if and else.
#include<stdio.h>
void main()
{
FILE *nd;
clrscr();...
|
by: Brian Blais |
last post by:
Hello,
I saw on a couple of recent posts people saying that casting the return
value of malloc is bad, like:
d=(double *) malloc(50*sizeof(double));
why is this bad? I had always thought...
|
by: erebus- |
last post by:
When learning the C programing languages, i have had and still am
having the problem of not being able to find answers to many
questions. Is their an overall guide/reference that someone knows?
|
by: jacob navia |
last post by:
I would like to add at the beginning of the C tutorial I am writing
a short blurb about what "types" are. I came up with the following text.
Please can you comment?
Did I miss something?
Is...
|
by: Sunny |
last post by:
Hi,
Well this might look like a dumb question to 99.99% of u but what
exactly is K&R2 and where can I get it?
Secondly alot of people say that you can learn by reading good books on
C. I know...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |