473,657 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strdup

According to a recent c.l.c++ flame war, the semi-ubiquitous-but-not-ANSI
strdup() function actually violates the C standard, because it is illegally
named. If this is true, what standard naming rule(s) does it violate?

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cybers pace.org |
Nov 13 '05 #1
11 6891
"Christophe r Benson-Manica" <at***@nospam.c yberspace.org> wrote in message
news:bk******** **@chessie.cirr .com...
According to a recent c.l.c++ flame war,
I wouldn't call that a 'flame war', but a few folks
disagreeing, and some learning. :-)
the semi-ubiquitous-but-not-ANSI
strdup() function actually violates the C standard, because it is illegally named.
Yes, it violates a reserved name constraint.
If this is true, what standard naming rule(s) does it violate?


<begin quote>

ISO/IEC 9899:1999 (E)

[...]

7.26 Future library directions

1 The following names are grouped under individual headers
for convenience. All external names described below are
reserved no matter what headers are included by the program.

[...]

7.26.11 String handling <string.h>

1 Function names that begin with str, mem,or wcs and a lowercase
letter may be added to the declarations in the <string.h> header.

<end quote>

This does imply to me that the identifers 'str', 'mem',
and 'wcs' are allowed. Anyone care to confirm or deny?

-Mike

-Mike
Nov 13 '05 #2
Mike Wahler <mk******@mkwah ler.net> spoke thus:
I wouldn't call that a 'flame war', but a few folks
disagreeing, and some learning. :-)
Some people "learning" more than others ;)

1 Function names that begin with str, mem,or wcs and a lowercase
letter may be added to the declarations in the <string.h> header.


So, in essence, this is saying that at some point the Standard may choose to
specify a standard strdup() function? Come to think of it, since strdup() is
widely used, why isn't it standard? It isn't implementation-specific (like,
say, htonl and such)...

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cybers pace.org |
Nov 13 '05 #3
In article <bk**********@c hessie.cirr.com >, Christopher Benson-Manica wrote:
According to a recent c.l.c++ flame war, the semi-ubiquitous-but-not-ANSI
strdup() function actually violates the C standard, because it is illegally
named. If this is true, what standard naming rule(s) does it violate?


Sections 7.26.10 and 7.26.11 of the C99 standard says that in
the future, functions that begin with "str" might be added to
the <stdlib.h> and <string.h> headers.

The rationale for 7.26 ends with "Users are advised that failure
to take heed of the points mentioned herein is considered
undesirable for a conforming program".
--
Andreas Kähäri
Nov 13 '05 #4
"Christophe r Benson-Manica" <at***@nospam.c yberspace.org> wrote in message
news:bk******** **@chessie.cirr .com...
Mike Wahler <mk******@mkwah ler.net> spoke thus:
I wouldn't call that a 'flame war', but a few folks
disagreeing, and some learning. :-)
Some people "learning" more than others ;)


Yep. :-)
1 Function names that begin with str, mem,or wcs and a lowercase
letter may be added to the declarations in the <string.h> header.


So, in essence, this is saying that at some point the Standard may choose

to specify a standard strdup() function?
It may choose to specify *any* external identifier which
begins with 'str' and a lowercase letter.

strdup, strthis, strthat, struptrouble, etc.
Come to think of it, since strdup() is
widely used, why isn't it standard?
You'll have to ask the committee members about that.
Such questions about 'why' etc. should be asked at
comp.std.c. Here we only discuss the language as it
is, not as it 'should be'.
It isn't implementation-specific
Yes, by definition, any function not specified by the
standard is implementation-specific. The fact that
many implementations might behave the same way doesn't
matter. In the case of 'strdup()' it's also a constraint
violation.
(like,
say, htonl and such)...


Those functions are by definition implementation-specific
as well.

E.g. I could write a 'htonl()' function which draws
pictures of naked women and emails them to your
pastor, and that would be perfectly legal according
to the standard (but probably not according to the
human laws of many jurisdictions. :-) )

It doesn't matter if everyone else's 'htonl()' function
did something else.
-Mike
Nov 13 '05 #5
Mike Wahler wrote:

[strdup()]
It isn't implementation-specific


Yes, by definition, any function not specified by the
standard is implementation-specific. The fact that
many implementations might behave the same way doesn't
matter. In the case of 'strdup()' it's also a constraint
violation.


I think he means that strdup() wouldn't require implementation-specific
stuff to be implemented, which would prevent the committee from
including it.


Brian Rodenborn
Nov 13 '05 #6
Christopher Benson-Manica <at***@nospam.c yberspace.org> wrote:
According to a recent c.l.c++ flame war, the semi-ubiquitous-but-not-ANSI
strdup() function actually violates the C standard, because it is illegally
named. If this is true, what standard naming rule(s) does it violate?


It's illegal for user code to define a function with that identifier -
but your C implementation is allowed to do so.

- Kevin

Nov 13 '05 #7
On Fri, 19 Sep 2003 20:11:59 GMT, "Mike Wahler"
<mk******@mkwah ler.net> wrote in comp.lang.c:
"Christophe r Benson-Manica" <at***@nospam.c yberspace.org> wrote in message
news:bk******** **@chessie.cirr .com...
According to a recent c.l.c++ flame war,


I wouldn't call that a 'flame war', but a few folks
disagreeing, and some learning. :-)
the semi-ubiquitous-but-not-ANSI
strdup() function actually violates the C standard, because it is

illegally
named.


Yes, it violates a reserved name constraint.


[snip]

Actually it is unclear to me whether an implementation that provides a
function named strdup() is conforming unless it provides a mechanism
for disabling the visibility of such a function.

But since the word "constraint " is conspicuously absent from this
section of the standard, it most certainly is not a constraint
violation.

Actually I posted a question about very issue, using strdup() as an
example, to comp.std.c yesterday. If there are any replies, they
haven't reached my ISP's news server yet.

The question is exactly to whom these names are reserved, to the
"implementation " for whatever use it cares to make of them, or
strictly for "future additions to the standard".

Since the use of an identifier with any of the reserved patterns and
external linkage in a program invokes undefined behavior, no strictly
conforming program can ever determine whether its implementation
defines such a non-standard function.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #8
On Fri, 19 Sep 2003 23:08:59 GMT, Kevin Easton
<kevin@-nospam-pcug.org.au> wrote in comp.lang.c:
Christopher Benson-Manica <at***@nospam.c yberspace.org> wrote:
According to a recent c.l.c++ flame war, the semi-ubiquitous-but-not-ANSI
strdup() function actually violates the C standard, because it is illegally
named. If this is true, what standard naming rule(s) does it violate?


It's illegal for user code to define a function with that identifier -
but your C implementation is allowed to do so.


I would love to see your reasoning for coming to that conclusion based
on the actual wording of the standard. I have always found it
ambiguous.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #9
Jack Klein <ja*******@spam cop.net> wrote:
On Fri, 19 Sep 2003 23:08:59 GMT, Kevin Easton
<kevin@-nospam-pcug.org.au> wrote in comp.lang.c:
Christopher Benson-Manica <at***@nospam.c yberspace.org> wrote:
> According to a recent c.l.c++ flame war, the semi-ubiquitous-but-not-ANSI
> strdup() function actually violates the C standard, because it is illegally
> named. If this is true, what standard naming rule(s) does it violate?


It's illegal for user code to define a function with that identifier -
but your C implementation is allowed to do so.


I would love to see your reasoning for coming to that conclusion based
on the actual wording of the standard. I have always found it
ambiguous.


As you mention in your reply, a strictly conforming program can't tell
whether or not the implementation does define such a function, so the
"the implementation is free to provide extensions as long as they don't
affect the meaning of any strictly conforming program" rule comes into
play.

- Kevin.

Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
23624
by: Allan Bruce | last post by:
Hi there, I have a program written in c++ and I wish to use a similar function to strdup(). The reason I have problems is that the char array requires freeing to avoid a memory leak, but I get problems using delete; e.g. char *NewCharArray;
6
2935
by: Stefan Schwärzler | last post by:
Hi Ng, habe nicht besonders viel Erfahrung in C und C++, deshalb: möchte den befehl strdup in <string.h> verwenden. #include <string.h> attrib(char *name, char *val) : name(strdup(name)), val(strdup(val)), next(0) { CDEBUG(printf("attrib::attrib(%s, %s)\n", name, val)); }
32
6366
by: Grumble | last post by:
As far as I can tell, strdup() is neither in C89 nor in C99. Is that correct? <OT>Is it in POSIX perhaps?</OT>
37
4295
by: priya | last post by:
Hi all, I am using strdup() in my c program..But I am having some pr0blem while using the free() in my c code.here I am pasting the my code. #include <stdio.h>
53
651
by: klaushuotari | last post by:
Sorry to bother you, but I just have to. What about strdup()? It wasn't in standard C run-time library, yet many apps use it liberally as it was in there. I don't know if that particular function is included in C99. Not too difficult to code own version of it, but why it wasn't included in library in the first place? Is there some rationale behind it? There are peculiar and dangerous functions like strtok(), so why not strdup() which...
20
6116
by: Michael Holm | last post by:
Ever so often when I try to compile some open source code, I get a error, pbrtparse.y(205) : error C3861: 'strdup': identifier not found In the example, I'm trying to compile pbrt (http://www.pbrt.org/). And I have been searching all over the net for it, and it seems I'm the only one having a problem with strdup. What do I do wrong?
5
3338
by: lovecreatesbea... | last post by:
I am trying the FREE net-snmp library things. Like the FREE libxml++ library, it lacks of a reasonable document on its API. Its very begining example code compiles and runs. It says "blah blah .." when I substitute the host address for a snmp equipped machine ``192.168.5.10'' within our LAN like this: session.peername = strdup("192.168.5.10"); Is strdup still in use? Is there anything prevents the code from becoming these:
10
3913
by: thomas | last post by:
Hi, It's known that strdup() returns a char* type, but sometimes the following code generates warning messages. char *x = ... char *p = strdup(x); You must change it to
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.