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)*
(In reply to comment #0) > 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.
(In reply to comment #1) > Yes 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'?
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.
(In reply to comment #3) > 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.
(In reply to comment #3) > 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.