News for hackers. Stuff that matters.
Re:Popular Myths about C++, Part 1 by throwawayaway on Tuesday December 09, 2014 @09:46AM (#8722951)
How can you have pointers without allowing all the holes that C allows?
Re:Popular Myths about C++, Part 1 by Ragnarork on Tuesday December 09, 2014 @10:15AM (#8723169)
By not using them like in C.

Of course this isn't an argument, but this shows that even though C++ doesn't prevent you from falling into the same trap that are present in C, it does give you the tool to at least allow you to do better than C to avoid these traps, notably thanks to RAII.

Oh and let's not forget nullptr, which is a blessing compared to NULL.

Pointers are still a feature of both languages.

Pointers in C++ are basically the same than in C, just with mechanisms that solve the ownership and some safety problems.

So yes, it allows the same holes, but at least you have tools to avoid falling in them.

Re:Popular Myths about C++, Part 1 by throwawayaway on Tuesday December 09, 2014 @11:10AM (#8723516)
You need to understand so much about C to even talk about pointers in C++, and everything related to them, it's not funny.

RAII -> Why? nullptr vs. NULL -> Why? Pointers -> Why? Don't use them in a certain way -> Why?

The answer in all cases is C.

Re:Popular Myths about C++, Part 1 by coldtea on Tuesday December 09, 2014 @03:24PM (#8725461)
>The answer in all cases is C.

Starting to sound like a broken record. No, the answer in all cases can also be found in C++, and understood in C++ terms alone. C++ is a SUPERSET of C, not just an arbitrary language + C.

Re:Popular Myths about C++, Part 1 by throwawayaway on Tuesday December 09, 2014 @06:44PM (#8726631)
cheers for the broken record warning.

i will now abstain from further conversation - i will leave you with this - i don't care to read your answer in case i have to respond and you might have to deal with some more repetition:

using the language of sets, the set of C++ minus the set of C, with what is now left:

how can you explain the things i have listed?

Re:Popular Myths about C++, Part 1 by coldtea on Wednesday December 10, 2014 @03:28AM (#8728238)
>how can you explain the things i have listed?

As evolution within the same language. Inconsistent ideas ironed out for more uniform and safer handling.

A lot of used languages have similar historical warts...

How do you explain "var" in JS, when "let" exists?

Re:Popular Myths about C++, Part 1 by pjmlp on Tuesday December 09, 2014 @03:16PM (#8725394)
No, they are C++ pointers.

There are endless languages that have pointers, no need to talk anything about C.

Re:Popular Myths about C++, Part 1 by pjmlp on Tuesday December 09, 2014 @09:51AM (#8723003)
By using them like safe system programming languages from Algol/Mesa line do.

Out function parameters are implicit pointers via references. Cannot be null.

Pointers and arrays aren't compatible.

Pointer arithmetic is frown upon and in many of those languages requires an explicit unsafe block/system module import.

Re:Popular Myths about C++, Part 1 by throwawayaway on Tuesday December 09, 2014 @09:54AM (#8723017)
would it be fair to say you have just described references, or do I have to go and lookup this algol/mesa stuff?
Re:Popular Myths about C++, Part 1 by pjmlp on Tuesday December 09, 2014 @05:33PM (#8726317)
Some examples using Modula-2, a Mesa's successor.

How it allows for all the C pointer features, while adding a little bit more safety.

    MODULE examples;
    IMPORT Terminal, SYSTEM;

    (* procedure with reference parameter, no need for pointers *)
    PROCEDURE ChangeParam (VAR changeMe: CARDINAL);
    BEGIN
      changeMe := 25;
    END ChangeParam;

    (* 
       procedure with a slice, bounds given by HIGH(changeMe) and LOW(changeMe).
       also a string in this case
       no need for explicit pointers
    *)
    PROCEDURE DumpLetters (VAR letters: ARRAY OF CHAR);
    VAR
      i : CARDINAL;
      
    BEGIN
      FOR i := 0 TO HIGH(letters) DO
         WriteChar(letters[i]);
      WriteLn;
      (* Or just use *)
      WriteString (letters);
    END DumpLetters;


    VAR
      anInt : CARDINAL := 12 ;
      aPtr : POINTER TO CHAR;
      aBuffer : ARRAY [1..2] OF CHAR;
      anAddr : ADDRESS; (* think void* *)
      aPtr2 : POINTER TO CHAR;
      
    BEGIN
      WriteInt(anInt); (* writes 12 *)
      ChangeParam (anInt);
      WriteInt(anInt); (* writes 25 *)
      DumpLetters ('A simple string');
      NEW(aPtr); (* The compiler knows the size, no need for sizeof, but you can use ALLOCATE(aPTR, SIZE(CHAR)) if you want *)
      
      (* This is where it shares the same problems with C, due to manual memory control  *)
      DISPOSE(aPtr); 
      
      (* do pointer arithmetic if really required *)
      anAddr := SYSTEM.ADDADR (SYSTEM.ADR(aBuffer), SIZE(CHAR) * 1); 
      aPtr2 := SYSTEM.CAST(POINTER TO CHAR, anAddr); (* aPtr2 now points to aBuffer(2) *)
    END examples;
So the compiler will mark this module as unsafe since the meta-package SYSTEM is being used.

All Modula-2 successors, have GC support, as such the DISPOSE() would have to be written as SYSTEM.DISPOSE() and could only be applied to untraced pointers.

Re:Popular Myths about C++, Part 1 by throwawayaway on Tuesday December 09, 2014 @06:55PM (#8726676)
very interesting, reminds me of this:

http://stackoverflow.com/questions/6456253/why-is-reference-...

it's a great shame it's defined in such an alien to use way in C++.

Re:Popular Myths about C++, Part 1 by pjmlp on Tuesday December 09, 2014 @10:02AM (#8723091)
I can provide a better example, but only tonight. At work now.