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));
}
Borland bringt dann die Meldung "undefinierte Funktion" 'strdup'
Müsste doch in string.h definiert sein. Oder macht hier Borland was anderes.
Danke für Eure Hilfe,
Stefan 6 2927
"Stefan Schwärzler" <st**************************@bmw.de> wrote in message
news:ch*********@usenet.bmw.de... 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)); }
Borland bringt dann die Meldung "undefinierte Funktion" 'strdup' Müsste doch in string.h definiert sein. Oder macht hier Borland was anderes.
Danke für Eure Hilfe,
Apparently, Borland C++ doesn't define strdup(), simply write it as:
char *strdup( const char *s )
{
char *dup = malloc(strlen(s) +1);
return strcpy(dup, s);
}
p.s: Next time it is better that you post to german c/c++ newsgroup next
time.
--
Elias
"Stefan Schwärzler" <st**************************@bmw.de> wrote in message
news:ch*********@usenet.bmw.de... Hi Ng,
.... #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)); }
Borland bringt dann die Meldung "undefinierte Funktion" 'strdup' Müsste doch in string.h definiert sein. Oder macht hier Borland was anderes.
The function "strdup" is not part of the C or C++ standards.
It is common on UNIX however, and part of some related
standards (e.g. http://tinyurl.com/46cp5 ).
Its typical implementation will look like:
char *strdup(const char *s)
{
size_t l = 1+strlen(s);
char* p = malloc(l);
if( !! p ) memcpy( p, s, l );
return p;
}
Since you are programming C++, however, I would recommend using
std::string instead, as it makes it easier to write safe and
correct code.
Also, when writing a post in German, you obviously should use
de.comp.lang.iso-c++ (maybe this was accidental?).
Cheers,
Ivan
-- http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
"lallous" <la*****@lgwm.org> wrote in message news:<2q************@uni-berlin.de>... "Stefan Schwärzler" <st**************************@bmw.de> wrote in message news:ch*********@usenet.bmw.de... 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)); }
Borland bringt dann die Meldung "undefinierte Funktion" 'strdup' Müsste doch in string.h definiert sein. Oder macht hier Borland was anderes.
Danke für Eure Hilfe,
Apparently, Borland C++ doesn't define strdup(), simply write it as:
char *strdup( const char *s ) { char *dup = malloc(strlen(s) +1); return strcpy(dup, s); }
That's C, in C++ better use std::string or if you think
it's really needed provide a wrapper class to avoid
confusion of operator new[]/delete[] (C++) with malloc/free (C).
[snip]
Stephan Brönnimann br****@osb-systems.com
Open source rating and billing engine for communication networks.
> The function "strdup" is not part of the C or C++ standards. It is common on UNIX however, and part of some related standards (e.g. http://tinyurl.com/46cp5 ). Its typical implementation will look like: char *strdup(const char *s) { size_t l = 1 + strlen(s); char* p = malloc(l); if( !! p ) memcpy( p, s, l ); return p; }
Hello Ivan,
Why do you use "if (!!p)" instead of "if (p)" or "if (p != 0)"?
--
Elias
"lallous" <la*****@lgwm.org> wrote in message
news:2q************@uni-berlin.de... char *strdup( const char *s ) { char *dup = malloc(strlen(s) +1); return strcpy(dup, s); }
NB: it is wise to check for a NULL return value of malloc
before calling strcpy, to avoid undefined behavior.
(Even though nowadays, we tend to forget about out-of-memory
conditions on our desktop platforms... )
Cheers,
Ivan
-- http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
"lallous" <la*****@lgwm.org> wrote in message
news:3b**************************@posting.google.c om... char *strdup(const char *s) { size_t l = 1 + strlen(s); char* p = malloc(l); if( !! p ) memcpy( p, s, l ); return p; }
.... Why do you use "if (!!p)" instead of "if (p)" or "if (p != 0)"?
That's really just a choice of style/notation.
"!!" is one of the ways to explicitly convert a value to a boolean.
Some like to enable compiler warnings when a non-boolean expression
is used within an if/while/...., so if(p) can be a problem.
if( p!=0 ) like if( p==0 ) are disliked by some because of the
risk of confusion/mistyping/... as if( p=0 ) .
This is why some will write if( 0!=p ) and if( 0==p ) .
Also there is the debate about the use of NULL instead of 0...
I came upon the use of "!!" a few years ago in some code I was reading.
I found it disturbing at first sight, then I felt it was a convenient
notation, easily read as a "cast-to-bool" operator.
It has become a habit of mine...
Cheers,
Ivan
-- http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steven O. |
last post by:
First, sorry if by some chance I am not posting to the correct
newsgroups, these seemed to be the most applicable to my question (see
disclaimer at end of post for further comments....).
Started...
|
by: TGF |
last post by:
I am wondering if it is feasible to use .NET for applications that have to
be very fast. We have a few applications that are blazingly fast, written
in Borland C++ using Borland C++ Builder. We...
|
by: Ziggi |
last post by:
Hi. I want to get a C++ IDE, but I dont know whether to go for Bill Gate's
solution or Borland's. Could any kind folks detail the relative strength
and weaknesses of both, and also tell me which...
|
by: Chris |
last post by:
I am just beginning programming again and need a bit of advice.
I have both Visual C++ 6.0 Standard Edition and Borland C++ Builder 6.
Of these two which do you consider the best for programming...
|
by: Christo |
last post by:
hey im a student about to start a course in c++ at uni, we have been told to
obtain a copy of borland c++ 5.01 (not c++ builder)
this is just a program with a compiler/linker and development...
|
by: serdar |
last post by:
Hi. Does anybody say that what is better borland c++ or visual c++?
Which compiler does have more help?
|
by: Xproblem |
last post by:
FTP Client Engine for C/C++ 2.4 Screenshot - Soft.comFTP Client Engine
for C/C++ 2.4. ... System Requirements: Windows C/C++ compiler -
Microsoft operating system: Windows 95, Windows 98, Windows...
|
by: smartwolf agassi via DotNetMonster.com |
last post by:
I'm a C# language learner.
I want to know which IDE is better for C# programing, Borland C#Builder or
VS.net 2003?
--
Message posted via http://www.dotnetmonster.com
|
by: Fabry |
last post by:
Hi All,
I'm new of this group and I do not know if this is the correct group
for my question.
I have a DLL with its export library (.lib) wrote in Borland C++ 6. In
borland everything is OK and...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
| |