Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #107890

Re: Need help fixing a "previously defined" error

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Need help fixing a "previously defined" error
Date 2017-04-08 15:17 -0400
Organization A noiseless patient Spider
Message-ID <ocbcqu$d7k$1@dont-email.me> (permalink)
References <20170408-130720.9.0@Peabody.ssl.astraweb.com> <ocat16$nro$1@dont-email.me> <20170408-175108.70.0@Peabody.ssl.astraweb.com>

Show all headers | View raw


On 04/08/2017 01:51 PM, Peabody wrote:
> James Kuyper says...
> 
>  > It declares that strtrim identifies a function that
>  > takes one argument of type char*, and returns a value of
>  > type char*. The "lpszA" is purely decorative as far as C
>  > itself is concerned. It uses prefixes that tell you
>  > something about the meaning of the string that it points
>  > at, but I'm not familiar with those prefixes.
> 
>  > Most likely because they used the Microsoft compiler,
>  > while you used LCC. The C standard gives implementations
>  > a lot of freedom to differ from each other, and
>  > "strtrim" is one example of that. strtrim() is NOT part
>  > of the C standard library, so this might seem to be a
>  > non-conforming implementation of <string.h>. However,
>  > 7.31.13 says that names beginning with "str", "mem", or
>  > "wcs" followed by a lower case letter may be added to
>  > future versions of <string.h>, and according to 7.1.3p1,
>  > all such names are therefore reserved for use as
>  > identifiers with external linkage. strtrim matches that
>  > pattern. Because such names are reserved, LCC is
>  > entitled to add such names to it's own version of
>  > <stdio.h>, and the TI code has undefined behavior.
>  > "Undefined behavior" means that Microsoft compiler is
>  > free to accept such code and have it execute exactly as
>  > expected, but it also means that LCC is allowed to
>  > reject such code.
> 
> Ok, but what's confusing me is that "StrTrim" is a legit
> Microsoft string function, although possibly (only) for C++:

C is case sensitive, so StrTrim is a completely different identfier from
strtrim.

> https://msdn.microsoft.com/en-us/library/windows/desktop/bb773454
> (v=vs.85).aspx
> 
> So is this just a mistake - the wrong case chosen for the
> letters - and TI is really trying to call the MS
> function to trim a string?

That's quite unlikely. It was probably intended to call some other
function named strtrim (and NOT StrTrim) to trim a string. That
particular name is fairly popular.

> ...  But what string would that be?

If you found no other occurrences of strtrim() in the code, then it
isn't currently being called for any string. In code that has been
around for a long time, this is not uncommon - there used to be a call
to strtrim(), but it got removed, but the person who removed it forgot
to remove the declaration for strtrm().

> "lpszA" doesn't appear anywhere else in the source code

As I said, that's purely decorative - it has no meaning that matters as
far as C code is concerned. In particular, it doesn't have to match
anything else (in fact, if if did match a macro name, the results could
be disastrous).

> either, but I think it also has some kind of special meaning
> involving Unicode.

No.

>  > The TI code declares strtrim(), but makes no use of it?
>  > That's weird, but unused declarations are not uncommon
>  > in code that has a lot of history. If so, that's trivial
>  > to deal with - just remove the declaration. If you made
>  > a mistake while searching for other uses of strtrim,
>  > removing that declaration will help you find them.
> 
> I did try that, and the compile worked.  But somehow I'm not
> comfortable with it not needing to be there.

Get comfortable with it when looking at other people's code - there's a
lot of sloppy coding practices out there. Removing all uses of a
declaration, without remembering to remove the declaration itself, is an
unfortunately common occurrence. In your own code you should try to
avoid doing that, but it's pretty much unavoidable in other people's code.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Need help fixing a "previously defined" error Peabody <waybackNO584SPAM44@yahoo.com> - 2017-04-08 08:07 -0500
  Re: Need help fixing a "previously defined" error James Kuyper <jameskuyper@verizon.net> - 2017-04-08 10:47 -0400
    Re: Need help fixing a "previously defined" error Peabody <waybackNO584SPAM44@yahoo.com> - 2017-04-08 12:51 -0500
      Re: Need help fixing a "previously defined" error Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-08 20:03 +0100
      Re: Need help fixing a "previously defined" error Spiros Bousbouras <spibou@gmail.com> - 2017-04-08 19:06 +0000
      Re: Need help fixing a "previously defined" error James Kuyper <jameskuyper@verizon.net> - 2017-04-08 15:17 -0400
  Re: Need help fixing a "previously defined" error Spiros Bousbouras <spibou@gmail.com> - 2017-04-08 15:29 +0000
  Re: Need help fixing a "previously defined" error Barry Schwarz <schwarzb@dqel.com> - 2017-04-08 09:21 -0700
    Re: Need help fixing a "previously defined" error Peabody <waybackNO584SPAM44@yahoo.com> - 2017-04-08 13:04 -0500
      Re: Need help fixing a "previously defined" error James Kuyper <jameskuyper@verizon.net> - 2017-04-08 15:33 -0400
        Re: Need help fixing a "previously defined" error Spiros Bousbouras <spibou@gmail.com> - 2017-04-08 19:51 +0000
        Re: Need help fixing a "previously defined" error Peabody <waybackNO584SPAM44@yahoo.com> - 2017-04-08 16:24 -0500
    Re: Need help fixing a "previously defined" error Keith Thompson <kst-u@mib.org> - 2017-04-08 18:45 -0700
  Re: Need help fixing a "previously defined" error bartc <bc@freeuk.com> - 2017-04-08 17:46 +0100
    Re: Need help fixing a "previously defined" error Peabody <waybackNO584SPAM44@yahoo.com> - 2017-04-08 13:19 -0500
  Re: Need help fixing a "previously defined" error David Brown <david.brown@hesbynett.no> - 2017-04-09 12:38 +0200
    Re: Need help fixing a "previously defined" error Peabody <waybackNO584SPAM44@yahoo.com> - 2017-04-09 07:52 -0500
      Re: Need help fixing a "previously defined" error David Brown <david.brown@hesbynett.no> - 2017-04-09 17:02 +0200
        Re: Need help fixing a "previously defined" error Peabody <waybackNO584SPAM44@yahoo.com> - 2017-04-09 18:20 -0500
          Re: Need help fixing a "previously defined" error James Kuyper <jameskuyper@verizon.net> - 2017-04-09 22:06 -0400
          Re: Need help fixing a "previously defined" error David Brown <david.brown@hesbynett.no> - 2017-04-10 09:07 +0200
            Re: Need help fixing a "previously defined" error Peabody <waybackNO584SPAM44@yahoo.com> - 2017-04-10 09:11 -0500
              Re: Need help fixing a "previously defined" error David Brown <david.brown@hesbynett.no> - 2017-04-10 17:31 +0200
                Re: Need help fixing a "previously defined" error Peabody <waybackNO584SPAM44@yahoo.com> - 2017-04-10 12:48 -0500

csiph-web