Results 1 to 3 of 3

Thread: Is this true? .:Resolved:.

  1. #1

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Is this true? .:Resolved:.

    I saw this message on another programming forum and I didn't agree with some of the things he was saying about C strings in C compared to C++ and some other comments. This was in responce to a newbie asking a question about programming. Any clarification would be great.

    I only suggest C because C++ starts to take power away from the programmer. I very much enjoy doing cstring manipulations. I find it very interesting. I have an assignment that can use some of my tools I have written in my data structures class (which must be in C++). I ran into this very irratating feature of C++. A line of code such as:


    Code:
    char *a = "Hello, world!";
    would produce a nice ready to use cstring that I can start manipulating that is compiled into the binary. However, in C++, that cstring is placed into (read only/const char*) memory. Not even a type cast fixes it. So I must waste my cycles dynamically putting the string into r/w memory. Little things like this that turn up turn me away from C++. Strong typing which forces you to type cast ANY conversion between datatypes is somewhat annoying. References take away from forcing a programmer to learn and use the power of pointers.

    Now don't get me wrong, these elements of C++ are great, really great for a big project that can have many errors that these syntax features will catch at the compilation level, but for learning reasons, one should really consider the power of a programming language to get the best understanding of what is going on. After I learned the very basics of C, I jumped into Java and then C++.
    Last edited by voidflux; Apr 17th, 2004 at 11:59 AM.
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This is WRONG!

    Whether a literal string is placed into modifiable memory or read-only memory is only a matter of compiler settings, never of the language. According to the standard I believe that compilers should default to RO in both languages, so this guy had it wrong for ages but only now stumbled upon his error because C++ is more typesafe.
    A line of code such as
    char *p = "Hello";
    therefore always was invalid with the default GCC or VC++ settings in C and C++, but both compilers emitted at best a warning about it.

    C++ doesn't take any power away from the programmer, but the programmer can choose to give up a little power in return for extreme usability enhancements.

    But honestly, you must be crazy to enjoy cstring manipulation and find it interesting. It's extremely dull, as this guy undoubtly will find out eventually.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290
    hah that is what I wanted to hear.

    Thanks!
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width