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(nam e)), val(strdup(val) ),
next(0) {
CDEBUG(printf(" attrib::attrib( %s, %s)\n", name, val));
}
Borland bringt dann die Meldung "undefinier te Funktion" 'strdup'
Müsste doch in string.h definiert sein. Oder macht hier Borland was anderes.
Danke für Eure Hilfe,
Stefan 6 2948
"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(nam e)), val(strdup(val) ), next(0) { CDEBUG(printf(" attrib::attrib( %s, %s)\n", name, val)); }
Borland bringt dann die Meldung "undefinier te 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(nam e)), val(strdup(val) ), next(0) { CDEBUG(printf(" attrib::attrib( %s, %s)\n", name, val)); }
Borland bringt dann die Meldung "undefinier te 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.is o-c++ (maybe this was accidental?).
Cheers,
Ivan
-- http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
"lallous" <la*****@lgwm.o rg> 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(nam e)), val(strdup(val) ), next(0) { CDEBUG(printf(" attrib::attrib( %s, %s)\n", name, val)); }
Borland bringt dann die Meldung "undefinier te 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.o rg> 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.o rg> wrote in message
news:3b******** *************** ***@posting.goo gle.com... 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 with the Borland web site, and it didn't answer my questions,
so I hope someone here will be kind enough to reply. I took a few
courses on C++ using Microsoft Visual C++, and then taught myself MFC
for GUI design -- an exercise akin to using...
|
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 would like to port over to
..NET, but some of the test models we have developed are MUCH, MUCH slower
than it's Borland counterpart. Is this due to the .NET Framework and the
JIT? Or is it something we should be looking for in the project...
|
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 you yourselves prefer.
Thanks in advance.
Ziggi
|
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 windows programs
(not the DOS style program). I have had a quick look at both of these and
Borland seems to have a lot more components (Buttons, Forms etc) than
Microsoft Visual C++. Does Visual C++ have these components easily
accesable.
Chris.
|
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 environment.
it is simply called borland c++ 5.01
can anyone tell me where i can download either a free copy or a copy that
needs registering or someething, i can only find c++ builder which is
totally different from the program i have seen in...
| |
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 ME, ...
www.soft30.com/screen-70-11625.htm - 31k - Cached - Similar pages
C++ Server Pages 1.6 - Soft.comC++ Server Pages (CSP) allows developers
to build Dynamic Web Pages and Web ... Existing C++ projects can be
ported to the Web by simply...
|
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 I am able to include the lib and use the
class that i have exported creating an instance with new etc... I
would like to export this class in microsoft VC++ using the same .lib
file. Obviously it doesn' t work.
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
| |
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |