MCENANEY WILLIAM J wrote:

> Hi Glynn, Thank you for your thoughts.  I agree with you.  For readability,
> the strings_equal function would be better than the conditional:
> 
>       if (strcmp (s1, s2) == SAME)
>          puts ("They're the same.");
>       else
>          puts ("They differ.");
> 
> This statement has, I think, a good point that the strings_equal function
> may not have.  My statement avoids the overhead of a function call.

If you declare strings_equal in a header file, and declare it as
`static inline', then there won't be any function call; it will be
inlined.

In any case, the overhead of a function call is trivial. The kind of
situation where it is useful to avoid function calls is where it
inhibits optimisations which would otherwise be possible (loop
induction being the obvious example).

> I'm sorry for writing a confusing letter.  I know how "=" differs from
> "==".  When I said that I would prefer an equal sign, I meant that in C,
> I would replace the strcmp() function with a relational equal sign.

That's what I presumed that you meant. In which case, what would you
use to test simply whether the pointers were equal, rather than
whether they pointed to identical strings?

> I have read that C programmers sometimes do so much low-level programming
> that they forget how to think very abstractly.

I don't think that they forget how to think in an abstract manner;
more likely, they don't use C if they want to work at an abstract
level. Personally, if I want a high degree of abstraction, I use Lisp
or Haskell, not C.

> I always try to think
> about objects and abstract data types.  The more generally I think, the more
> information I can hide.  Although I'm only beginning to learn object-
> oriented programming, I've always tried to make my subprograms like black
> boxes.  You put something into a box.  Another thing pops out, but you
> don't need to know what happens in the box.

Abstraction is useful, but sometimes it is necessary to deal with the
underlying details.

Back to the case in point, there is a difference between an object and
a reference to it. Specifically, if two pointers are equal, then
modifications via one of the pointers to will be visible via the other
pointer.

The same concept is embodied in Lisp, where you have both `eq' (which
tells you whether the arguments refer to the same object), and `equal'
(which tells you whether the objects are equal). Likewise with Java;
you have both `==' (reference equality) and `equals' (value equality).

The only languages where there is no difference are pure functional
languages (e.g. Haskell, Hope), where there is no notion of mutable
state.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to