digitalmars.D - Is this a bug ?
- Binarydepth (35/35) Nov 28 2013 Here is my code : It compiles but in run time terminal shows a
- Adam D. Ruppe (4/6) Nov 28 2013 This should be writef instead of write. writef uses the format
- Binarydepth (4/11) Nov 28 2013 Right forgot to change that. I'm passing C code to D code and D
- Adam D. Ruppe (2/3) Nov 28 2013 linux
- bearophile (6/9) Nov 28 2013 A statically typed language should give a compile-time error for
- Adam D. Ruppe (3/5) Nov 28 2013 It is perfectly valid to pass a string to the write function. He
- Binarydepth (8/13) Nov 28 2013 Yeah it's ok for the function but it will print %d: %d, and then
- bearophile (4/6) Nov 29 2013 Sorry.
Here is my code : It compiles but in run time terminal shows a segmentation fault. Am I doing something wrong ? Or do I have to file a Bug ? -------------------------------------------------------------------- import std.stdio : write, readf; void funcion(int a, int t) { int temp, bd, an; temp=t; temp*=20; temp+=402; temp*=5; temp+=3; bd=temp-a; temp=t; temp*=5; temp+=50; temp*=20; temp+=1013; an=temp-a; write(" %d: %d\n", bd, an); } void main() { int r, f, count, b; write("Input your birth year : "); readf(" %d", &b); readf(" %d %d", &r, &f); for(count=r; count<=f; count++) { funcion(b, count); } } ---------------------------------------------------------------------------------
Nov 28 2013
On Friday, 29 November 2013 at 00:35:30 UTC, Binarydepth wrote:It compiles but in run time terminal shows a segmentation fault.works for me without segfaulting. What data did you input?write(" %d: %d\n", bd, an);This should be writef instead of write. writef uses the format string, plain write just literally outputs its arguments.
Nov 28 2013
On Friday, 29 November 2013 at 00:40:29 UTC, Adam D. Ruppe wrote:On Friday, 29 November 2013 at 00:35:30 UTC, Binarydepth wrote:Right forgot to change that. I'm passing C code to D code and D code to C code and still make those mistakes. So weird I get seg fault. which OS are you using ?It compiles but in run time terminal shows a segmentation fault.works for me without segfaulting. What data did you input?write(" %d: %d\n", bd, an);This should be writef instead of write. writef uses the format string, plain write just literally outputs its arguments.
Nov 28 2013
On Friday, 29 November 2013 at 01:17:36 UTC, Binarydepth wrote:So weird I get seg fault. which OS are you using ?linux
Nov 28 2013
Adam D. Ruppe:A statically typed language should give a compile-time error for such mistake. It's a leftover from the weakly typed C mindset. In many cases format strings are known at compile-time. Bye, bearophilewrite(" %d: %d\n", bd, an);This should be writef instead of write. writef uses the format string, plain write just literally outputs its arguments.
Nov 28 2013
On Friday, 29 November 2013 at 01:35:31 UTC, bearophile wrote:A statically typed language should give a compile-time error for such mistake.It is perfectly valid to pass a string to the write function. He simply called the wrong function.
Nov 28 2013
On Friday, 29 November 2013 at 01:37:15 UTC, Adam D. Ruppe wrote:On Friday, 29 November 2013 at 01:35:31 UTC, bearophile wrote:Yeah it's ok for the function but it will print %d: %d, and then the values of the following variables. without a new line. And actually I was intending to translate that line to write function but I forgot. I prefer the write function I simply write : write(var, var, "\n"); or writeln(var, var); much better than formatting everything. :)A statically typed language should give a compile-time error for such mistake.It is perfectly valid to pass a string to the write function. He simply called the wrong function.
Nov 28 2013
Adam D. Ruppe:It is perfectly valid to pass a string to the write function. He simply called the wrong function.Sorry. Bye, bearophile
Nov 29 2013