Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Is the aliasing rule symmetric?

Reply
Thread Tools

Is the aliasing rule symmetric?

 
 
dSpam@arcor.de
Guest
Posts: n/a
 
      02-16-2011
On 9 Feb., 02:51, Joshua Maurice <(E-Mail Removed)> wrote:
> http://www.open-std.org/jtc1/sc22/wg...ocs/dr_236.htm
>
> This defect report, and it's resolution, is what triggered most of
> this discussion for me. Let me phrase another reinterpretation of the
> same problem.
>
> Consider the following program. myMalloc and myFree are intended to be
> drop in replacements of malloc and free. They are written entirely in
> portable C code, in userspace, and are written on top of malloc and
> free. I hope that and would argue that such functions ought to be
> writable.
>
> * #include <stdio.h>
> * void* myMalloc(size_t );
> * void myFree(void* );
> * int main()
> * {
> * * int* a = 0;
> * * float* b = 0;
>
> * * a = myMalloc(sizeof *a);
> * * *a = 1;
> * * printf("%d\n", *a);
> * * myFree(a);
>
> * * b = myMalloc(sizeof *b);
> * * *b = 1;
> * * printf("%f\n", *b);
> * * myFree(b);
> * }
>
> It is possible that myMalloc will return the same pointer value for
> both requests. In that case, the program behaves basically exactly as
> if:
> ...
>
> * #include <stdio.h>
> * #include <stdlib.h>
> * int main()
> * {
> * * void* myMemoryPool = 0;
> * * int* a = 0;
> * * float* b = 0;
>
> * * myMemoryPool = malloc(sizeof(int) + sizeof(float));
>
> * * a = myMemoryPool;
> * * b = myMemoryPool;
>
> * * *a = 1;
> * * printf("%d\n", *a);
>
> * * *b = 1;
> * * printf("%f\n", *b);
> * }
>
> Which one may (?) be able to rewrite as:
>
> * #include <stdio.h>
> * #include <stdlib.h>
> * void foo(int* a, float* b)
> * {
> * * *a = 1;
> * * printf("%d\n", *a);
>
> * * *b = 1;
> * * printf("%f\n", *b);
> * }
> * int main()
> * {
> * * void* myMemoryPool = 0;
> * * int* a = 0;
> * * float* b = 0;
>
> * * myMemoryPool = malloc(sizeof(int) + sizeof(float));
>
> * * a = myMemoryPool;
> * * b = myMemoryPool;
> * * foo(a, b);
> * }
>
> Which is the union DR, aka
> *http://www.open-std.org/jtc1/sc22/wg...ocs/dr_236.htm
>
> Which step broke it? When we introduced the function foo, or an
> earlier step? I await a more formalized answer to that DR.


I mean it was when introducing the function foo.
A more formalized answer to DR 236 is indeed desirable.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is the aliasing rule symmetric? Johannes Schaub (litb) C++ 68 02-06-2011 09:33 PM
Is the aliasing rule symmetric? Johannes Schaub (litb) C++ 2 01-21-2011 11:30 PM
how to add validation rule for url in the validation-rule.xml ,I added some thing like this but......... shailajabtech@gmail.com Java 0 10-12-2006 08:36 AM
Anti-aliasing GIF Images Kevin Bertman Java 4 11-29-2004 05:46 AM
LCD anti-aliasing in Java Tim Tyler Java 2 09-05-2003 09:01 AM



Advertisments