digitalmars.D.learn - new to D2.0 , invariant problem
- MikeRJ (11/12) Nov 19 2008 For some reason i think DM 1.0 is slowly dieing as i see tons of new fea...
- Jesse Phillips (10/28) Nov 19 2008 bool open(char[] fn, char[] mode="rb".dup) {
- Kagamin (8/15) Nov 20 2008 D1 and D2 compatible code:
- Steven Schveighoffer (8/23) Nov 20 2008 The correct const-contract usage is:
For some reason i think DM 1.0 is slowly dieing as i see tons of new features in D 2.0's phobos not implemented in D 1.0 so im trying to migrate to D2.0 my 1st problem is when i compile code: bool open(char[] fn, char[] mode="rb") { filename=fn.dup; file = fopen(toStringz(filename), toStringz(mode)); if (!file) return false; return true; } i receive error:can anyone help here. thanks in advance.cannot implicitly convert expression ("rb") of type invariant(char[2u]) to char[]|
Nov 19 2008
On Wed, 19 Nov 2008 22:10:50 -0500, MikeRJ wrote:For some reason i think DM 1.0 is slowly dieing as i see tons of new features in D 2.0's phobos not implemented in D 1.0 so im trying to migrate to D2.0 my 1st problem is when i compile code: bool open(char[] fn, char[] mode="rb") { filename=fn.dup; file = fopen(toStringz(filename), toStringz(mode)); if (!file) returnfalse; return true; } i receive error:bool open(char[] fn, char[] mode="rb".dup) { will probably make it compile, but since you are using D2 I think the correct methodology would be: bool open(string fn, string mode="rb") { Since you don't make changes to fn or mode they should be invariant. Also, D1 is not dieing, it is not supposed to get any new features. D2 is continually changing which would not be good if you are doing application development.can anyone help here. thanks in advance.cannot implicitly convert expression ("rb") of type invariant(char[2u]) to char[]|
Nov 19 2008
MikeRJ Wrote:bool open(char[] fn, char[] mode="rb") { filename=fn.dup; file = fopen(toStringz(filename), toStringz(mode)); if (!file) return false; return true; }D1 and D2 compatible code: bool open(in char[] fn, in char[] mode="rb") { file = fopen(toStringz(fn), toStringz(mode)); if (!file) return false; return true; }
Nov 20 2008
"MikeRJ" wroteFor some reason i think DM 1.0 is slowly dieing as i see tons of new features in D 2.0's phobos not implemented in D 1.0 so im trying to migrate to D2.0 my 1st problem is when i compile code: bool open(char[] fn, char[] mode="rb") { filename=fn.dup; file = fopen(toStringz(filename), toStringz(mode)); if (!file) return false; return true; } i receive error:The correct const-contract usage is: bool open(const(char)[] fn, const(char)[] mode = "rb") That is, you are saying open does not modify fn or mode. It simply uses them as input parameters. The D1/D2 compatible version that Kagamin posted is also legal (and pretty much the same thing). -Stevecan anyone help here. thanks in advance.cannot implicitly convert expression ("rb") of type invariant(char[2u]) to char[]|
Nov 20 2008