Thread: language design question

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595

    language design question

    Is there a reason why you have to use strcmp for C-style strings as opposed to ==?

    Also, why isn't there a function/operator to compare arrays in the standard?

    I'm sure there are good reasons why the language was designed this way, but just wondering why?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Is there a reason why you have to use strcmp for C-style strings as opposed to ==?
    You can't overload operators for built in types. And because C-style strings are arrays, they decay to pointers when used in an expression. Thus, using == for both string comparison and pointer comparison would be ambiguous. You could come up with rules such as "== means string comparison with the arrays are of type char *", but that would hurt a lot of low level code that treats objects as strings of char. So the reason is that it would cause more trouble than it's worth.

    >Also, why isn't there a function/operator to compare arrays in the standard?
    There is, memcmp.
    Last edited by Prelude; 04-12-2004 at 09:54 AM.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program design question
    By Chaplin27 in forum C++ Programming
    Replies: 1
    Last Post: 06-23-2005, 07:18 PM
  2. program design question
    By Chaplin27 in forum C++ Programming
    Replies: 0
    Last Post: 06-23-2005, 06:58 PM
  3. simple simple design question
    By Chaplin27 in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2005, 11:33 PM
  4. Constructor failed: design question
    By registering in forum C++ Programming
    Replies: 9
    Last Post: 07-01-2003, 03:29 PM
  5. Replies: 4
    Last Post: 11-19-2002, 09:18 PM