strdup in c++ 
July 19th, 2005, 06:56 PM
| | | |
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;
NewCharArray = strdup("Some text");
delete []NewCharArray;
Nybody have any ideas?
Thanks
Allan | 
July 19th, 2005, 06:56 PM
| | | | re: strdup in c++
"Allan Bruce" <allanmb@TAKEAWAYf2s.com> wrote in message news:bkcbc5$hr6$1@news.freedom2surf.net...[color=blue]
> 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;
>
> NewCharArray = strdup("Some text");
>
> delete []NewCharArray;
>
>
> Nybody have any ideas?[/color]
std::string NewString;
NewString = "SomeText";
// delete not required. | 
July 19th, 2005, 06:56 PM
| | | | re: strdup in c++
Allan Bruce wrote:[color=blue]
> 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;
>
> NewCharArray = strdup("Some text");
>
> delete []NewCharArray;
>
>
> Nybody have any ideas?[/color]
Nybody must be some Scandinavian guy :-)
Use std::string instead of fiddling with those arrays.
--
Attila aka WW | 
July 19th, 2005, 06:56 PM
| | | | re: strdup in c++
"Allan Bruce" <allanmb@TAKEAWAYf2s.com> wrote
[color=blue]
> 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[];[/color]
You have to use free:
#include <cstdlib>
#include <cstring>
// ...
char * NewCharArray = strdup ("Hi there");
// std::strdup doesn't compile on my machine
// (macro?). Good job I never use it.
std::free (NewCharArray);
But don't do that. Use the standard string class.
Regards,
Buster | 
July 19th, 2005, 06:56 PM
| | | | re: strdup in c++
"Buster" <noone@nowhere.com> wrote in message
news:bkcecp$9u3$1@news7.svr.pol.co.uk...[color=blue]
> "Allan Bruce" <allanmb@TAKEAWAYf2s.com> wrote
>[color=green]
> > I have a program written in c++ and I wish to use a[/color][/color]
similar function to[color=blue][color=green]
> > strdup().
> > The reason I have problems is that the char array[/color][/color]
requires freeing to avoid[color=blue][color=green]
> > a memory leak, but I get problems using delete[];[/color]
>
> You have to use free:[/color]
<snip>
<OT> strdup( ) isn't even a standard C or C++ function.
Whether you should use free or delete[] depends on what the
particular compiler vendor's strdup( ) used to allocate the
memory </OT> | 
July 19th, 2005, 06:56 PM
| | | | re: strdup in c++
"John Ericson" <jericson@pacbell.net> wrote[color=blue]
> <OT> strdup( ) isn't even a standard C or C++ function.
> Whether you should use free or delete[] depends on what the
> particular compiler vendor's strdup( ) used to allocate the
> memory </OT>[/color]
I'm learning a lot today. Thanks. | 
July 19th, 2005, 06:56 PM
| | | | re: strdup in c++
"Buster" <noone@nowhere.com> wrote in message news:bkcecp$9u3$1@news7.svr.pol.co.uk...
[color=blue]
> // ...
> char * NewCharArray = strdup ("Hi there");
> // std::strdup doesn't compile on my machine
> // (macro?). Good job I never use it.[/color]
That's because there is no std::strdup. strdup
is not a standard C or C++ function. | 
July 19th, 2005, 06:56 PM
| | | | re: strdup in c++
"Allan Bruce" <allanmb@TAKEAWAYf2s.com> wrote in
news:bkcbc5$hr6$1@news.freedom2surf.net:
[color=blue]
> 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;
>
> NewCharArray = strdup("Some text");
>
> delete []NewCharArray;
>
>
> Nybody have any ideas?[/color]
Two ideas:
1) As others have mentioned, use std::string in preference (generally) to
char*'s.
2) Remember to always delete[] what you new[], and to free() what you
malloc() (or calloc(), or strdup(), or other functions which are
documented to requrire free()ing of the memory obtained). Under the
covers, strdup() effectively calls malloc() (I don't know if this is
strictly mandated). So, in order to correctly dispose of the memory
obtained by strdup(), your code should be:
char * NewCharArray = strdup("Some text");
free(NewCharArray);
(Depressingly, I had to look up whether free needed the parens, or does
it get called like delete... It's been so long since I've used
malloc/free.... :) ) | 
July 19th, 2005, 06:56 PM
| | | | re: strdup in c++
John Ericson wrote:[color=blue]
> "Buster" <noone@nowhere.com> wrote in message
> news:bkcecp$9u3$1@news7.svr.pol.co.uk...
>[color=green]
>>"Allan Bruce" <allanmb@TAKEAWAYf2s.com> wrote
>>
>>[color=darkred]
>>>I have a program written in c++ and I wish to use a[/color][/color]
>
> similar function to
>[color=green][color=darkred]
>>>strdup().
>>>The reason I have problems is that the char array[/color][/color]
>
> requires freeing to avoid
>[color=green][color=darkred]
>>>a memory leak, but I get problems using delete[];[/color]
>>
>>You have to use free:[/color]
>
>
> <snip>
>
> <OT> strdup( ) isn't even a standard C or C++ function.
> Whether you should use free or delete[] depends on what the
> particular compiler vendor's strdup( ) used to allocate the
> memory </OT>[/color]
SMACK the supplier over the head if they don't use malloc/free.
Use free() to release memory allocated by strdup().
If you're using C++ you'd be far better off using std::string. | 
July 19th, 2005, 06:57 PM
| | | | re: strdup in c++
"Allan Bruce" <allanmb@TAKEAWAYf2s.com> wrote in message
news:bkcbc5$hr6$1@news.freedom2surf.net...[color=blue]
> Hi there,
>
> I have a program written in c++ and I wish to use a similar function to
> strdup().[/color]
Note that 'strdup()' is not part of standard C++ (or C).
[color=blue]
> The reason I have problems is that the char array requires freeing to[/color]
avoid[color=blue]
> a memory leak, but I get problems using delete[];[/color]
IMO the reason you're having problems is that you're using
arrays of characters (with all their traps and pitfalls) and
dynamic allocation (with its possible problems) when you should
be using the 'std::string' type to represent strings.
std::string my_strdup(const std::string& s)
{
return s;
}
void foo()
{
std::string x(my_strdup("abc"));
}
But doing this is silly, since the same effect can be
achieved with simpler (and probably more efficient)
code:
std::string s1("abc"); /* 'duplicates' "abc" in the string 's1' */
std::string s2(s1); /* 'duplicates' 's1' contents in 's2' */
s1 = s2; /* 'duplicates' 's2' contents in 's1' */
/* etc */
[color=blue]
> e.g.
>
> char *NewCharArray;[/color]
This name is misleading. 'NewCharArray' is not an array,
it's a pointer.
[color=blue]
>
> NewCharArray = strdup("Some text");[/color]
Why not simply:
char NewCharArray[] = {"Some text"};
[color=blue]
>
> delete []NewCharArray;[/color]
Then you don't need this.
[color=blue]
>
>
> Nybody have any ideas?[/color]
Yes, stop trying to use C++ to write C code. :-)
IF you need a string, the C++ library has a very
powerful and easy to use string type which is much
safer than arrays of characters and messing with
allocation and deallocation.
-Mike | 
July 19th, 2005, 06:57 PM
| | | | re: strdup in c++
"Andre Kostur" <nntpspam@kostur.net> wrote in message
news:Xns93FA5614EB469nntpspamkosturnet@209.53.75.2 1...[color=blue]
> "Allan Bruce" <allanmb@TAKEAWAYf2s.com> wrote in
> news:bkcbc5$hr6$1@news.freedom2surf.net:
>[color=green]
> > 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;
> >
> > NewCharArray = strdup("Some text");
> >
> > delete []NewCharArray;
> >
> >
> > Nybody have any ideas?[/color]
>
> Two ideas:
>
> 1) As others have mentioned, use std::string in preference (generally) to
> char*'s.
>
> 2) Remember to always delete[] what you new[], and to free() what you
> malloc() (or calloc(), or strdup(), or other functions which are
> documented to requrire free()ing of the memory obtained). Under the
> covers, strdup() effectively calls malloc() (I don't know if this is
> strictly mandated).[/color]
Of course not, since it's not a standard function. One should
follow its documentation for correct usage. This 'correct usage'
could be different among implementations.
[color=blue]
>So, in order to correctly dispose of the memory
> obtained by strdup(), your code should be:
>
> char * NewCharArray = strdup("Some text");
>
> free(NewCharArray);[/color]
Only if the particular implementation of 'strdup()' being
used documents to do it that way.
[color=blue]
>
> (Depressingly, I had to look up whether free needed the parens, or does
> it get called like delete... It's been so long since I've used
> malloc/free.... :) )[/color]
malloc and free are functions, so argument list must always
be enclosed in parens:
p = malloc(whatever);
free(p);
new, new[], delete, and delete[] are operators, and do
not need parens.
p = new int;
delete p;
-Mike | 
July 19th, 2005, 06:57 PM
| | | | re: strdup in c++
"Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkcjbe$p2h@dispatch.concentric.net...
[color=blue][color=green]
> > <OT> strdup( ) isn't even a standard C or C++ function.
> > Whether you should use free or delete[] depends on what the
> > particular compiler vendor's strdup( ) used to allocate the
> > memory </OT>[/color]
>
> SMACK the supplier over the head if they don't use malloc/free.[/color]
They have to supply malloc / free. There's no telling what the
function strdup() requires because there's no such function in
standard C or C++. | 
July 19th, 2005, 06:57 PM
| | | | re: strdup in c++
"Mike Wahler" <mkwahler@mkwahler.net> wrote in news:Dgmab.7671$UN4.3734
@newsread3.news.pas.earthlink.net:
[color=blue]
>
> "Allan Bruce" <allanmb@TAKEAWAYf2s.com> wrote in message
> news:bkcbc5$hr6$1@news.freedom2surf.net...[color=green]
>> Hi there,
>>
>> I have a program written in c++ and I wish to use a similar function to
>> strdup().[/color]
>
> Note that 'strdup()' is not part of standard C++ (or C).[/color]
Huh. Hadn't realized that. Only that every implementation I've used has
had a strdup.... oh well. Answer rephrase: check the documentation on your
particular implementation of strdup(). All of the implementations I've
used, the memory returned by strdup() needs to be free()'d. YMMV | 
July 19th, 2005, 06:58 PM
| | | | re: strdup in c++
Ron Natalie wrote:[color=blue]
> "Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkcjbe$p2h@dispatch.concentric.net...
>
>[color=green][color=darkred]
>>><OT> strdup( ) isn't even a standard C or C++ function.
>>>Whether you should use free or delete[] depends on what the
>>>particular compiler vendor's strdup( ) used to allocate the
>>>memory </OT>[/color]
>>
>>SMACK the supplier over the head if they don't use malloc/free.[/color]
>
>
> They have to supply malloc / free. There's no telling what the
> function strdup() requires because there's no such function in
> standard C or C++.[/color]
Sure there is. It's in every man page for strdup. | 
July 19th, 2005, 06:58 PM
| | | | re: strdup in c++
Gianni Mariani wrote:[color=blue][color=green]
>> They have to supply malloc / free. There's no telling what the
>> function strdup() requires because there's no such function in
>> standard C or C++.[/color]
>
> Sure there is. It's in every man page for strdup.[/color]
Man pages do not define the C or the C++ language. The international
standards do. And they do not contain strdup. So there is no strdup in
standard C or C++.
--
WW aka Attila | 
July 19th, 2005, 06:58 PM
| | | | re: strdup in c++
Gianni Mariani wrote:
[color=blue]
> Ron Natalie wrote:
>[color=green]
>>
>> They have to supply malloc / free. There's no telling what the
>> function strdup() requires because there's no such function in
>> standard C or C++.[/color]
>
>
> Sure there is. It's in every man page for strdup.
>[/color]
I assume you mean "Sure there is a way of telling what strdup()
requires", not "Sure there is such a function in standard C or C++."
From the point of view of either language, there is no way to to tell,
since the function is outside the scope of the languages (and this group).
Technically, the function itself is illegal in C because it uses a
reserved name ('str' followed by a lowercase letter - reserved for
future standard library use). I don't know if this applies in C++, where
future library functions may be in std:: rather than the global namespace.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting. | 
July 19th, 2005, 06:59 PM
| | | | re: strdup in c++
White Wolf wrote:[color=blue]
> Gianni Mariani wrote:
>[color=green][color=darkred]
>>>They have to supply malloc / free. There's no telling what the
>>>function strdup() requires because there's no such function in
>>>standard C or C++.[/color]
>>
>>Sure there is. It's in every man page for strdup.[/color]
>
>
> Man pages do not define the C or the C++ language. The international
> standards do. And they do not contain strdup. So there is no strdup in
> standard C or C++.
>[/color]
There is a clear definition of what strdup should do. If you change
that all code that uses it breaks. It's highly unlikely that anyone
will do anything different. It's a de-facto standard.
For the longest time C was a defacto standard. In fact even now, C was
for a longer time NOT a standard that it is a standard without any help
from a standards body.
Standards are great, we have so many of them !
So what if there is no international standard to cite. If you write
somthing that breaks everyone's code, you'll need a smack in the head too. | 
July 19th, 2005, 06:59 PM
| | | | re: strdup in c++
Gianni Mariani wrote:[color=blue]
> White Wolf wrote:[color=green]
>> Gianni Mariani wrote:
>>[color=darkred]
>>>> They have to supply malloc / free. There's no telling what the
>>>> function strdup() requires because there's no such function in
>>>> standard C or C++.
>>>
>>> Sure there is. It's in every man page for strdup.[/color]
>>
>>
>> Man pages do not define the C or the C++ language. The international
>> standards do. And they do not contain strdup. So there is no
>> strdup in standard C or C++.
>>[/color]
>
> There is a clear definition of what strdup should do.[/color]
There is a clear definition of what strdup does on that system you were
looking at. There is no clear definiton of what strdup does in C or C++,
except that it is illegaly named.
[color=blue]
> If you change
> that all code that uses it breaks.[/color]
If I change the function foo() all the code what uses it will break. That
does not make it standard C or C++ function.
[color=blue]
> It's highly unlikely that anyone
> will do anything different. It's a de-facto standard.[/color]
Probably. But if you look at the name of this newsgroup, it is not
comp.lang.de-facto.c++
[color=blue]
> For the longest time C was a defacto standard. In fact even now, C
> was for a longer time NOT a standard that it is a standard without
> any help from a standards body.[/color]
Really? I remember those times. And I do not want them back.
[color=blue]
> Standards are great, we have so many of them ![/color]
This is irrelevant here. There is one C++ standard.
[color=blue]
> So what if there is no international standard to cite.[/color]
Irrelevant. There is one.
[color=blue]
> If you write somthing that breaks everyone's code,
> you'll need a smack in the head[/color]
Irrelevant. You have stated that strdup is standard C++ and it is not. The
rest is irrelevant.
--
WW aka Attila | 
July 19th, 2005, 06:59 PM
| | | | re: strdup in c++
> > If you write somthing that breaks everyone's code,[color=blue][color=green]
> > you'll need a smack in the head[/color][/color]
At the risk of taking this fun to a higher level...
....Let's remember why we are here. C++ exists to permit scalable yet
efficient projects. For the latter cause, the compiler frequently makes you
work harder than other languages would.
To become better than just dangerous at C++, you must learn the paths thru
its mine-field; a sane-subset.
Much rhetoric on this newsgroup derives from the attitude that one must know[color=blue]
>exactly< which statements are legal, which are truly portable, which
>should< be portable, and which you can get away with.[/color]
This newsgroup's greatest service is teaching that attitude.
--
Phlip http://www.greencheese.org/PhilosophyBrethrenThree | 
July 19th, 2005, 07:00 PM
| | | | re: strdup in c++
"Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkdfrh$p2m@dispatch.concentric.net...
[color=blue][color=green]
> > They have to supply malloc / free. There's no telling what the
> > function strdup() requires because there's no such function in
> > standard C or C++.[/color]
>
> Sure there is. It's in every man page for strdup.
>[/color]
What is in the man page for strdup? Despite whatever you are
looking at, strdup is not addressed by any C or C++ standard. | 
July 19th, 2005, 07:00 PM
| | | | re: strdup in c++
"Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkdl7n$p2i@dispatch.concentric.net...
[color=blue]
> For the longest time C was a defacto standard. In fact even now, C was
> for a longer time NOT a standard that it is a standard without any help
> from a standards body.[/color]
I have been programming C since 1977. I am well aware of the history.
We've had a standard for over ten years for C. strdup is not now nor has
it ever been part of it. As a matter of fact, if you were to define a function
called strdup, you'd be in violation of the standard. | 
July 19th, 2005, 07:00 PM
| | | | re: strdup in c++
Ron Natalie wrote:[color=blue]
> "Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkdl7n$p2i@dispatch.concentric.net...
>
>[color=green]
>>For the longest time C was a defacto standard. In fact even now, C was
>>for a longer time NOT a standard that it is a standard without any help
>>from a standards body.[/color]
>
>
> I have been programming C since 1977. I am well aware of the history.
> We've had a standard for over ten years for C. strdup is not now nor has
> it ever been part of it. As a matter of fact, if you were to define a function
> called strdup, you'd be in violation of the standard.[/color]
That's all very nice ... and totally meaningless in this discussion.
Disclaimer: In no way am I advocating people use strdup.
What I am saying is that it DOES EXIST and it is well known what it
should do. THEREFORE: answers to arguments about wether you need to use
new/delete or malloc/free are well defined. A corollary is that anyone
who would implement/suggest that strdup does something differently and
incompatible needs a brain adjustment.
If you can't agree with the statement above, we'll just have to agree to
disagree because right now I can't see how someone reasonable could
disagree and be reasonable. | 
July 19th, 2005, 07:00 PM
| | | | re: strdup in c++
Ron Natalie wrote:[color=blue]
> "Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkdfrh$p2m@dispatch.concentric.net...
>
>[color=green][color=darkred]
>>>They have to supply malloc / free. There's no telling what the
>>>function strdup() requires because there's no such function in
>>>standard C or C++.[/color]
>>
>>Sure there is. It's in every man page for strdup.
>>[/color]
>
> What is in the man page for strdup?[/color]
Lifted from the man page:
The strdup() function returns a pointer to a new string which is a
duplicate of the string s. Memory for the new string is obtained with
malloc(3), and can be freed with free(3).
Despite whatever you are[color=blue]
> looking at, strdup is not addressed by any C or C++ standard.[/color]
That's nice. | 
July 19th, 2005, 07:00 PM
| | | | re: strdup in c++
Gianni Mariani wrote:
[...][color=blue]
> Disclaimer: In no way am I advocating people use strdup.[/color]
strdup() is the standard XSI function... what? off-topic? give me a break.
[color=blue]
>
> What I am saying is that it DOES EXIST and it is well known what it
> should do.[/color]
Right on. "well known" http://www.opengroup.org/onlinepubs/...ns/strdup.html
regards,
alexander. | 
July 19th, 2005, 07:00 PM
| | | | re: strdup in c++
"Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkf894$elv@dispatch.concentric.net...
[color=blue]
>
> What I am saying is that it DOES EXIST and it is well known what it
> should do.[/color]
It is not well known in the terms of C or C++. It is only well known in
the terms of certain UNIX-like systems. If you want to persue this
silly assed line of logic further, take it to comp.os.unix. | 
July 19th, 2005, 07:00 PM
| | | | re: strdup in c++
"Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkf8d9$elm@dispatch.concentric.net...[color=blue]
> Ron Natalie wrote:[color=green]
> > "Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkdfrh$p2m@dispatch.concentric.net...
> >
> >[color=darkred]
> >>>They have to supply malloc / free. There's no telling what the
> >>>function strdup() requires because there's no such function in
> >>>standard C or C++.
> >>
> >>Sure there is. It's in every man page for strdup.
> >>[/color]
> >
> > What is in the man page for strdup?[/color]
>
> Lifted from the man page:
>
> The strdup() function returns a pointer to a new string which is a
> duplicate of the string s. Memory for the new string is obtained with
> malloc(3), and can be freed with free(3).
>[/color]
What bearing does that have to do with standard C or C++.[color=blue]
>
> Despite whatever you are[color=green]
> > looking at, strdup is not addressed by any C or C++ standard.[/color]
>
> That's nice.
>[/color]
Not only is it nice, it's fucking topical. Despite the fact I've been
working with UNIX and C since 1977, I've also worked with C and
C++ on a half dozen operating systems that didn't pretend to be
UNIX. If you want to drivel on about POSIX, take it to a UNIX
group. | 
July 19th, 2005, 07:00 PM
| | | | re: strdup in c++
Ron Natalie wrote:[color=blue]
> "Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkf894$elv@dispatch.concentric.net...
>
>[color=green]
>>What I am saying is that it DOES EXIST and it is well known what it
>>should do.[/color]
>
>
> It is not well known in the terms of C or C++. It is only well known in
> the terms of certain UNIX-like systems. If you want to persue this
> silly assed line of logic further, take it to comp.os.unix.[/color]
This all started becuase of this:
Ron Natalie wrote:
....[color=blue]
>
> They have to supply malloc / free. There's no telling what the
> function strdup() requires because there's no such function in
> standard C or C++.[/color]
The world is much bigger than the C and C++ standards. Spreading
mis-information about other facets is just plain wrong.
If you wish to hold this NG as close to the C++ standard as possible
that's an admirable goal but PLEASE refrain from discussing anything
else like you have above and we'll then be able to limit the "silly
assed" logic as you so nicely put it. | 
July 19th, 2005, 07:00 PM
| | | | re: strdup in c++
Ron Natalie wrote:
[...][color=blue][color=green][color=darkred]
> > > looking at, strdup is not addressed by any C or C++ standard.[/color]
> >
> > That's nice.
> >[/color]
> Not only is it nice, it's fucking topical.[/color]
Bah bah bah.
[color=blue]
> Despite the fact I've been
> working with UNIX and C since 1977, I've also worked with C and
> C++ on a half dozen operating systems that didn't pretend to be
> UNIX. If you want to drivel on about POSIX, take it to a UNIX
> group.[/color]
The problem is that "POSIX.1++" thing doesn't exist, yet.
Anything related to C++ is, currently, fucking UNtopical
topic in a UNIX group.
regards,
alexander. | 
July 19th, 2005, 07:01 PM
| | | | re: strdup in c++
Ron Natalie wrote:[color=blue]
> "Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkf8d9$elm@dispatch.concentric.net...
>[color=green]
>>Ron Natalie wrote:
>>[color=darkred]
>>>"Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkdfrh$p2m@dispatch.concentric.net...
>>>
>>>
>>>
>>>>>They have to supply malloc / free. There's no telling what the
>>>>>function strdup() requires because there's no such function in
>>>>>standard C or C++.
>>>>
>>>>Sure there is. It's in every man page for strdup.
>>>>
>>>
>>>What is in the man page for strdup?[/color]
>>
>>Lifted from the man page:
>>
>>The strdup() function returns a pointer to a new string which is a
>>duplicate of the string s. Memory for the new string is obtained with
>>malloc(3), and can be freed with free(3).
>>[/color]
>
> What bearing does that have to do with standard C or C++.[/color]
You asked what the man page says. Wether this has any bearing or not is
not part of this discussion and quite irrelevant.
[color=blue]
>[color=green]
>> Despite whatever you are
>>[color=darkred]
>>>looking at, strdup is not addressed by any C or C++ standard.[/color]
>>
>>That's nice.
>>[/color]
>
> Not only is it nice, it's fucking topical.[/color]
No it's not topical. You mis-stated something in an earlier post. All
this thread is about is a correction to your incorrect statement.
Despite the fact I've been[color=blue]
> working with UNIX and C since 1977, I've also worked with C and
> C++ on a half dozen operating systems that didn't pretend to be
> UNIX. If you want to drivel on about POSIX, take it to a UNIX
> group.[/color]
The NG is about the C++ standard, please post job experience to alt.jobs. | 
July 19th, 2005, 07:01 PM
| | | | re: strdup in c++
"Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkfckt$elm@dispatch.concentric.net...
[color=blue]
> You asked what the man page says. Wether this has any bearing or not is
> not part of this discussion and quite irrelevant.[/color]
The implicication was what did the man page say that had to do with the
statement that strdup isn't standard C or C++. Which is the statement
of mine you were attempting to refute with "it's in the man page." | 
July 19th, 2005, 07:01 PM
| | | | re: strdup in c++
Ron Natalie wrote:[color=blue]
> "Gianni Mariani" <gi2nospam@mariani.ws> wrote in message news:bkfckt$elm@dispatch.concentric.net...
>
>[color=green]
>>You asked what the man page says. Wether this has any bearing or not is
>>not part of this discussion and quite irrelevant.[/color]
>
>
> The implicication was what did the man page say that had to do with the
> statement that strdup isn't standard C or C++. Which is the statement
> of mine you were attempting to refute with "it's in the man page."[/color]
I wrote it ambiguously ... many apologies. This is what it's meant to say.
....... restated ......
You asked what the man page says and I gave it to you. strdup() being
part of the C++ stanard or not has no bearing on this discussion and is
quite irrelevant to this thread.
........ end .......
I hope it's less ambiguous now. | 
July 19th, 2005, 07:01 PM
| | | | re: strdup in c++
Gianni Mariani wrote:[color=blue]
> The world is much bigger than the C and C++ standards. Spreading
> mis-information about other facets is just plain wrong.[/color]
The world is. This newsgroup is not. Suggesting that it is A OK to use
strdup because it exists everywhere where C or C++ exists is wrong.
--
WW aka Attila | 
July 19th, 2005, 07:01 PM
| | | | re: strdup in c++
Where are the topless girls with the Round 2 sign?
--
WW aka Attila | 
July 19th, 2005, 07:02 PM
| | | | re: strdup in c++
White Wolf wrote:[color=blue]
> Gianni Mariani wrote:
>[color=green]
>>The world is much bigger than the C and C++ standards. Spreading
>>mis-information about other facets is just plain wrong.[/color]
>
>
> The world is. This newsgroup is not. Suggesting that it is A OK to use
> strdup because it exists everywhere where C or C++ exists is wrong.[/color]
When did you stop bashing your wife ? | 
July 19th, 2005, 07:02 PM
| | | | re: strdup in c++
"Gianni Mariani" <gi2nospam@mariani.ws> wrote[color=blue]
> When did you stop bashing your wife ?[/color]
It's, "Have you stopped beating your wife?".
It only works if it's a yes-no question. | 
July 19th, 2005, 07:02 PM
| | | | re: strdup in c++
Buster wrote:[color=blue]
> "Gianni Mariani" <gi2nospam@mariani.ws> wrote
>[color=green]
>>When did you stop bashing your wife ?[/color]
>
>
> It's, "Have you stopped beating your wife?".
> It only works if it's a yes-no question.[/color]
I stand corrected. I'm glad someone knew what I meant :^) | 
July 19th, 2005, 07:03 PM
| | | | re: strdup in c++
Gianni Mariani wrote:[color=blue][color=green]
>> The world is. This newsgroup is not. Suggesting that it is A OK to
>> use strdup because it exists everywhere where C or C++ exists is
>> wrong.[/color]
>
> When did you stop bashing your wife ?[/color]
L. Ron Hubbard is back.
I have no wife.
--
WW aka Attila | 
July 19th, 2005, 07:03 PM
| | | | re: strdup in c++
Buster wrote:[color=blue]
> "Gianni Mariani" <gi2nospam@mariani.ws> wrote[color=green]
>> When did you stop bashing your wife ?[/color]
>
> It's, "Have you stopped beating your wife?".
> It only works if it's a yes-no question.[/color]
And used heavily by L. Ron Hubbard, the founder of Scientology, to
demonstrate verbal oppression. I note this, because while I have read many
things in my life this question was only mentioned in his works.
--
WW aka Attila | 
July 19th, 2005, 07:03 PM
| | | | re: strdup in c++
In article <bkcbc5$hr6$1@news.freedom2surf.net>, allanmb@TAKEAWAYf2s.com
says...[color=blue]
> Hi there,
>
> I have a program written in c++ and I wish to use a similar function to
> strdup().[/color]
[ ... ]
[color=blue]
> Nybody have any ideas?[/color]
Yes. Use std::string and be done with it.
--
Later,
Jerry.
The universe is a figment of its own imagination. | 
July 19th, 2005, 07:04 PM
| | | | re: strdup in c++
WW wrote:[color=blue]
> Gianni Mariani wrote:
>[color=green][color=darkred]
>>>The world is. This newsgroup is not. Suggesting that it is A OK to
>>>use strdup because it exists everywhere where C or C++ exists is
>>>wrong.[/color]
>>
>>When did you stop bashing your wife ?[/color]
>
>
> L. Ron Hubbard is back.
>
> I have no wife.[/color]
QED. |  |
Similar Threads | | Thread | Thread Starter | Forum | Replies | Last Post | | strdup in Borland C++Builder | Stefan Schwärzler | answers | 6 | July 22nd, 2005 08:02 PM | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|