News for hackers. Stuff that matters.
Re:Why I haven't given up on C++ by IshKebab on Monday February 15, 2016 @03:55AM (#11102241)
I do like C++, but I do find myself more and more finding bugs that would have picked up in another language.

"Huh. I'm pretty sure Rust would have picked me up on that bug."

Here's an example. I accidentally wrote this:

    while (getLine(pc, buffer, sizeof(buffer) > 0))
Which compiles fine. Stricter languages could detect this bug.
Re:Why I haven't given up on C++ by CyberDildonics on Monday February 15, 2016 @07:19AM (#11102915)
Most compilers should give a warning about this.

Of course warnings work until you have source from something external that throws lots of warnings that you can't reliably turn off (possibly due to completely broken and ignored warning bugs in ICC for example).

Re:Why I haven't given up on C++ by mpweiher on Monday February 15, 2016 @05:09AM (#11102524)
Most likely two bugs. The bracket one, and the fact that sizeof(buffer) will give you the pointer size, not the buffer size if buffer is a pointer rather than an array.
Re:Why I haven't given up on C++ by eddyb on Monday February 15, 2016 @05:29AM (#11102595)
The first one would be caught in Rust as it has no integer -> boolean automatic conversions (similar to Java).

The second one could only arise with unsafe pointers in Rust, as safe code uses slices, combining the base pointer and the element count in a single value.

Re:Why I haven't given up on C++ by masklinn on Monday February 15, 2016 @05:35AM (#11102602)
> The second one could only arise with unsafe pointers in Rust, as safe code uses slices, combining the base pointer and the element count in a single value.

OTOH the point here is to pass a preallocated but "uninitialised" buffer to the callee, which Rust wouldn't allow with slices, unless you created a slice from a raw allocation (I don't know if that's defined behaviour, though I guess you could do that safely by passing in a Write rather than the slice itself, but then you're Write-ing to a slice which has… interesting behaviour)

Re:Why I haven't given up on C++ by dancsi on Monday February 15, 2016 @06:41AM (#11102781)
Your second point depends, in fact, on whether buffer was allocated statically.
Re:Why I haven't given up on C++ by mpweiher on Monday February 15, 2016 @06:53PM (#11106966)
Er, no.

   #include <stdio.h>

   static char buffer[80];
   static char *bufferp=buffer;

   int main(int argc, char *argv[] )
   {
	char localbuffer[80];
	char *localbufferp=localbuffer;
	printf("buffer: %ld\n",sizeof buffer);
	printf("bufferp: %ld\n",sizeof bufferp);
	printf("localbuffer: %ld\n",sizeof localbuffer);
	printf("localbufferp: %ld\n",sizeof localbufferp);
   } 
Output:

   marcel@sarek[tmp]./a.out 
   buffer: 80
   bufferp: 8
   localbuffer: 80
   localbufferp: 8

As you can see, it depends entirely on whether you give sizeof the array or the pointer.
Re:Why I haven't given up on C++ by IshKebab on Friday February 19, 2016 @05:09AM (#11132662)
`buffer` was indeed an array, not a pointer. The bug was the bracket!