Topic: assertiveness support from the compiler - making assertions quicker for function parameters
Author: bsingharora@gmail.com
Date: Fri, 21 Jan 2005 22:25:57 CST Raw View
===================================== MODERATOR'S COMMENT:
Please do quote an appropriate amount of context information when
posting replies.
===================================== END OF MODERATOR'S COMMENT
I am not directly subtracting pointers here. I am casting them to
caddr_t (character address type). Essentially the subtraction is
integer address subtraction. I think that should be ok looking at the
prototype and description of memcpy.
SYNOPSIS
#include <string.h>
void* memcpy(void *OUT, const void *IN, size_t N);
DESCRIPTION
This function copies N bytes from the memory region
pointed to by IN to the memory region pointed to by OUT.
Balbir
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kanze@gabi-soft.fr
Date: Tue, 25 Jan 2005 23:06:28 CST Raw View
Alberto Barbati wrote:
> bsingharora@gmail.com wrote:
> > if (abs((caddr_t)dst - (caddr_t)src)) < n)) {
> > return NULL;
> > }
> I hope you realize that the line above incurs in undefined
> behaviour unless both pointers points to elements of the same
> array ( 5.7/6), so it not a generally valid solution.
Obviously. On the other hand, we're talking about code which
would go inside a standard function, say in a debugging version
of the library. So it is sufficient that the code works on the
target implementation.
--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S mard, 78210 St.-Cyr-l' cole, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: bsingharora@gmail.com
Date: Thu, 20 Jan 2005 22:37:59 CST Raw View
Hello, All,
This is my first post to the news group. Of late, I was wondering if it
would be a good idea to add compiler supported assert's for function
parameters.
For example - consider the memcpy function.
Its prototype is
void *memcpy(void *dst, const void *src, size_t n);
This function does not work for overlapping memory areas. This could be
checked
inside memcpy as
if (abs((caddr_t)dst - (caddr_t)src)) < n)) {
return NULL;
}
if we could add compiler support at the declaration stage to change the
prototype as
void *memcpy(void *dst, const void *n, size_t n [(n >= abs((caddr_t)dst
- (caddr_t)src), NULL)]);
Note that since we use all parameters in the assert, the last parameter
should be parsed before the assert can be specified.
The advantages of this approach are that
1. The function need not be called if the assert condition is going to
fail, this would prevent the function call overhead.
2. Reading the function prototype tells the programmer as to how the
function parameters will be used.
The proposed extension allows for a condition, return value pair to be
added to each parameter. This specification is optional. If at the time
of calling the function, any of the condition fails (going from left to
right), the return value for the first failed condition is used as
return value of the function.
These are just first thoughts and not very formal. I can write up the
grammar and try to implement it with some existing compiler to see how
well this scheme works if the group is interested.
I am not sure if this technique has been used earlier, if it has -- I
would be glad if someone could point me to the original source. If not,
please let me know your comments?
Balbir Singh
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: nesotto@cs.auc.dk ("Thorsten Ottosen")
Date: Fri, 21 Jan 2005 07:59:21 GMT Raw View
| Hello, All,
|
| This is my first post to the news group. Of late, I was wondering if it
| would be a good idea to add compiler supported assert's for function
| parameters.
I think it is. Have you read`
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2004/n1669.html
?
br
-Thorsten
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: bsingharora@gmail.com
Date: Fri, 21 Jan 2005 11:23:41 CST Raw View
Thanks for the link. No, I have not seen this draft before. I will read
the paper, it looks very nicely done (from the short reading I did). I
will get back if I have any comments
Balbir Singh
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]