digitalmars.D.learn - About const and C functions
- bearophile (8/8) Mar 01 2011 Do you know why DMD doesn't give a compilation error here?
- Bekenn (3/11) Mar 01 2011 I'm not sure that's checkable. I think this falls squarely into the
- bearophile (6/8) Mar 02 2011 The signature of sscanf is something like:
- Bekenn (3/4) Mar 02 2011 With an annotation on the function signature, perhaps, and certainly it
- Trass3r (2/8) Mar 02 2011 What's the D signature of sscanf?
Do you know why DMD doesn't give a compilation error here? import core.stdc.stdio: sscanf; immutable int value = 5; void main() { sscanf("10".ptr, "%d".ptr, &value); } Bye, bearophile
Mar 01 2011
On 3/1/2011 2:33 PM, bearophile wrote:Do you know why DMD doesn't give a compilation error here? import core.stdc.stdio: sscanf; immutable int value = 5; void main() { sscanf("10".ptr, "%d".ptr,&value); } Bye, bearophileI'm not sure that's checkable. I think this falls squarely into the realm of "undefined behavior".
Mar 01 2011
Bekenn:I'm not sure that's checkable. I think this falls squarely into the realm of "undefined behavior".The signature of sscanf is something like: int sscanf(char* str, char* format, ...); Can't D/DMD err on the side of safety and consider the C-style variadic argument as not const, and so produce an error if you give to them something that's D const/immutable (and require a cast there)? (Especially a function like sscanf where the third and successive arguments are known to be modified). Bye, bearophile
Mar 02 2011
On 3/2/11 4:06 AM, bearophile wrote:Can't D/DMD err on the side of safety and consider the C-style variadic argument as not const, and so produce an error if you give to them something that's D const/immutable (and require a cast there)? (Especially a function like sscanf where the third and successive arguments are known to be modified).With an annotation on the function signature, perhaps, and certainly it should do this at all times in code marked safe.
Mar 02 2011
Am 01.03.2011, 23:33 Uhr, schrieb bearophile <bearophileHUGS lycos.com>:Do you know why DMD doesn't give a compilation error here? import core.stdc.stdio: sscanf; immutable int value = 5; void main() { sscanf("10".ptr, "%d".ptr, &value); }What's the D signature of sscanf?
Mar 02 2011
On 02/03/2011 08:56, Trass3r wrote:Am 01.03.2011, 23:33 Uhr, schrieb bearophile <bearophileHUGS lycos.com>:void* after the format arg... -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.ukDo you know why DMD doesn't give a compilation error here? import core.stdc.stdio: sscanf; immutable int value = 5; void main() { sscanf("10".ptr, "%d".ptr, &value); }What's the D signature of sscanf?
Mar 02 2011
On 02/03/2011 11:28, Simon wrote:On 02/03/2011 08:56, Trass3r wrote:Rather it's the ellipses, which is effectively void* -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.ukAm 01.03.2011, 23:33 Uhr, schrieb bearophile <bearophileHUGS lycos.com>:void* after the format arg...Do you know why DMD doesn't give a compilation error here? import core.stdc.stdio: sscanf; immutable int value = 5; void main() { sscanf("10".ptr, "%d".ptr, &value); }What's the D signature of sscanf?
Mar 02 2011