digitalmars.D.bugs - [Issue 5251] New: Const C file
- d-bugmail puremagic.com (35/35) Nov 21 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5251
- d-bugmail puremagic.com (14/16) Nov 22 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5251
- d-bugmail puremagic.com (10/12) Nov 22 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5251
- d-bugmail puremagic.com (16/16) Nov 22 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5251
- d-bugmail puremagic.com (7/21) Nov 22 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5251
- d-bugmail puremagic.com (15/18) Nov 22 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5251
http://d.puremagic.com/issues/show_bug.cgi?id=5251
Summary: Const C file
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Keywords: rejects-valid
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
I think this program is supposed to work, because fprintf() and fclose() don't
modify 'fout':
import std.c.stdio: fopen, fclose, fprintf;
void main() {
const fout = fopen("test.txt", "w");
fprintf(fout, "%d", 10); // ERR
fclose(fout); // ERR
}
But DMD 2.050 shows the errors:
test.d(4): Error: function core.stdc.stdio.fprintf (shared(_iobuf)* stream, in
const(char*) format,...) is not callable using argument types
(const(shared(const(_iobuf))*),string,int)
test.d(4): Error: cannot implicitly convert expression (fout) of type
const(shared(const(_iobuf))*) to shared(_iobuf)*
test.d(5): Error: function core.stdc.stdio.fclose (shared(_iobuf)* stream) is
not callable using argument types (const(shared(const(_iobuf))*))
test.d(5): Error: cannot implicitly convert expression (fout) of type
const(shared(const(_iobuf))*) to shared(_iobuf)*
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 21 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5251
Steven Schveighoffer <schveiguy yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |schveiguy yahoo.com
Resolution| |INVALID
08:58:52 PST ---
I think this program is supposed to work, because fprintf() and fclose() don't
modify 'fout':
Yes they do. fprintf and fclose deal with a memory-allocated buffer that will
be used to optimize I/O throughput.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 22 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5251Yes they do. fprintf and fclose deal with a memory-allocated buffer that will be used to optimize I/O throughput.If this bug report is invalid then thank you for closing it. I am not expert enough on this. But I don't understand what you have said. Even if fprintf and fclose deal with a memory-allocated buffer, do they modify the value of 'fout'? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 22 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5251
10:11:55 PST ---
const is transitive, so if you imagine a FILE having this structure:
struct FILE
{
int fd;
ubyte[] buffer;
}
Now, if FILE is const, then buffer is const(ubyte[]), so how does fprintf write
to that buffer?
What you are looking for is head-const (the variable cannot change, but
everything it points to can), which has some good uses, but does not exist in
D.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 22 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5251
const is transitive, so if you imagine a FILE having this structure:
struct FILE
{
int fd;
ubyte[] buffer;
}
Now, if FILE is const, then buffer is const(ubyte[]), so how does fprintf write
to that buffer?
What you are looking for is head-const (the variable cannot change, but
everything it points to can), which has some good uses, but does not exist in
D.
I understand, you are right, thank you.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 22 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5251
nfxjfg gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nfxjfg gmail.com
What you are looking for is head-const (the variable cannot change, but
everything it points to can), which has some good uses, but does not exist in
D.
It exists to some degree in D1:
final int[] a = [1,2];
a[0] = 1; //works
a = [5,6]; //Error: cannot modify final variable 'a'
Apparently this was disabled in D2.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 22 2010









d-bugmail puremagic.com 