Re: About const and C functions

2011-03-02 Thread Trass3r

Am 01.03.2011, 23:33 Uhr, schrieb bearophile bearophileh...@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?


Re: About const and C functions

2011-03-02 Thread Simon

On 02/03/2011 08:56, Trass3r wrote:

Am 01.03.2011, 23:33 Uhr, schrieb bearophile bearophileh...@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?


void* after the format arg...

--
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


Re: About const and C functions

2011-03-02 Thread Simon

On 02/03/2011 11:28, Simon wrote:

On 02/03/2011 08:56, Trass3r wrote:

Am 01.03.2011, 23:33 Uhr, schrieb bearophile bearophileh...@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?


void* after the format arg...



Rather it's the ellipses, which is effectively void*

--
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


Re: About const and C functions

2011-03-02 Thread bearophile
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


Re: About const and C functions

2011-03-02 Thread Bekenn

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.


About const and C functions

2011-03-01 Thread bearophile
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