dev-cpp-users Mailing List for Dev-C++ (Page 407)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(15) |
Oct
(115) |
Nov
(154) |
Dec
(258) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
(377) |
Feb
(260) |
Mar
(249) |
Apr
(188) |
May
(152) |
Jun
(150) |
Jul
(195) |
Aug
(202) |
Sep
(200) |
Oct
(286) |
Nov
(242) |
Dec
(165) |
| 2002 |
Jan
(245) |
Feb
(241) |
Mar
(239) |
Apr
(346) |
May
(406) |
Jun
(369) |
Jul
(418) |
Aug
(357) |
Sep
(362) |
Oct
(597) |
Nov
(455) |
Dec
(344) |
| 2003 |
Jan
(446) |
Feb
(397) |
Mar
(515) |
Apr
(524) |
May
(377) |
Jun
(387) |
Jul
(532) |
Aug
(364) |
Sep
(294) |
Oct
(352) |
Nov
(295) |
Dec
(327) |
| 2004 |
Jan
(416) |
Feb
(318) |
Mar
(324) |
Apr
(249) |
May
(259) |
Jun
(218) |
Jul
(212) |
Aug
(259) |
Sep
(158) |
Oct
(162) |
Nov
(214) |
Dec
(169) |
| 2005 |
Jan
(111) |
Feb
(165) |
Mar
(199) |
Apr
(147) |
May
(131) |
Jun
(163) |
Jul
(235) |
Aug
(136) |
Sep
(84) |
Oct
(88) |
Nov
(113) |
Dec
(100) |
| 2006 |
Jan
(85) |
Feb
(119) |
Mar
(33) |
Apr
(31) |
May
(56) |
Jun
(68) |
Jul
(18) |
Aug
(62) |
Sep
(33) |
Oct
(55) |
Nov
(19) |
Dec
(40) |
| 2007 |
Jan
(22) |
Feb
(49) |
Mar
(34) |
Apr
(51) |
May
(66) |
Jun
(43) |
Jul
(116) |
Aug
(57) |
Sep
(70) |
Oct
(69) |
Nov
(97) |
Dec
(86) |
| 2008 |
Jan
(32) |
Feb
(47) |
Mar
(106) |
Apr
(67) |
May
(28) |
Jun
(39) |
Jul
(31) |
Aug
(25) |
Sep
(18) |
Oct
(25) |
Nov
(5) |
Dec
(21) |
| 2009 |
Jan
(33) |
Feb
(27) |
Mar
(27) |
Apr
(22) |
May
(22) |
Jun
(10) |
Jul
(17) |
Aug
(9) |
Sep
(21) |
Oct
(13) |
Nov
(4) |
Dec
(11) |
| 2010 |
Jan
(10) |
Feb
(8) |
Mar
(4) |
Apr
(1) |
May
|
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(26) |
Nov
(9) |
Dec
(1) |
| 2011 |
Jan
(21) |
Feb
(16) |
Mar
(4) |
Apr
(19) |
May
(26) |
Jun
(9) |
Jul
(6) |
Aug
|
Sep
(4) |
Oct
(3) |
Nov
(2) |
Dec
(1) |
| 2012 |
Jan
(4) |
Feb
(7) |
Mar
(4) |
Apr
|
May
(1) |
Jun
(10) |
Jul
(1) |
Aug
(1) |
Sep
(18) |
Oct
(3) |
Nov
(1) |
Dec
(1) |
| 2013 |
Jan
(4) |
Feb
(2) |
Mar
(15) |
Apr
(6) |
May
(1) |
Jun
(3) |
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
|
Nov
(9) |
Dec
|
| 2014 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(5) |
Aug
(4) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(4) |
| 2015 |
Jan
(2) |
Feb
(3) |
Mar
(1) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(2) |
Oct
(9) |
Nov
(35) |
Dec
(6) |
| 2016 |
Jan
(7) |
Feb
(10) |
Mar
(10) |
Apr
(9) |
May
(13) |
Jun
(9) |
Jul
(1) |
Aug
(3) |
Sep
(3) |
Oct
(1) |
Nov
(1) |
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
(1) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Daniel K. O. <dan...@ya...> - 2003-04-03 04:00:47
|
> when i checked a lot of big project's source codes, I have found them
> replacing basic funtion names with new function names, and
> sometimes with a
> new way of functioning for example:
>
> free() -> OPENSSL_free()
> malloc() -> gnew(type, number of blocks)
>
> how can this be useful ?, does it have a thing to do with
> portability ?, and
> if not what's the difference in functionality ?
For libraries, it can have some conveniences, like:
----------
#define g_new(struct_type, n_structs) \
((struct_type *) g_malloc (((gsize) sizeof (struct_type)) * ((gsize)
(n_structs))))
----------
So you'll use it like
----------
struct foo { ... };
struct foo* many_foos = g_new(foo, 10);
----------
instead of
----------
many_foos = malloc(sizeof(foo) * 10);
or
many_foos = calloc(sizeof(foo), 10);
----------
Using macros, you can also include debuggin info, like:
---------
#ifdef DEBUG_INFO
#define my_malloc(n) \
(alloc_bytes++,malloc(n))
#else
#define my_malloc malloc
#endif
---------
or
---------
#ifdef DEBUG_INFO
#define my_free my_debugged_free
#else
#define my_free free
#endif
void my_debugged_free(void* p)
{
if (!p) {
puts("Hey you stupid, your're trying to free(NULL)!");
abort();
} else
free(p);
}
---------
So it's easy to track programming errors.
Daniel K. O.
It's OK to be ignorant; it's not OK to play stupid.
http://www.catb.org/~esr/faqs/smart-questions.html
|
|
From: picca <jas...@ho...> - 2003-04-03 03:51:02
|
i need program for name database!!!! |
|
From: Khalid El-K. <kha...@ho...> - 2003-04-03 02:57:06
|
hi fellows, when i checked a lot of big project's source codes, I have found them replacing basic funtion names with new function names, and sometimes with a new way of functioning for example: free() -> OPENSSL_free() malloc() -> gnew(type, number of blocks) how can this be useful ?, does it have a thing to do with portability ?, and if not what's the difference in functionality ? thanx in advance Regards, Khalid Al-Kary _________________________________________________________________ Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail |
|
From: Paul P. <P.P...@cu...> - 2003-04-03 02:48:36
|
Hi all Does anyone know of a way to determine if a user is currently logged on in a win2k environment? Paul Penley Assistant Computer Systems Administrator School of Psychology Curtin University of Technology P.P...@cu... Ph: +61 8 9266 7840 Fax: +61 8 9266 2464 Cricos provider Code 00301J |
|
From: Khalid El-K. <kha...@ho...> - 2003-04-03 01:05:34
|
Hi fellows, right now i know that memory in the stack gets allocated for once during the start-up of the programm, and dynamically allocated memory gets allocated while the programm is running. stack memory is faster at execution. dynamic memory is slower (the time consumed by malloc/free) but ... I want to know when exactly should i use stack memory and when exactly should i use dynamic memory ? thanx in advance Regards, Khalid Al-Kary _________________________________________________________________ MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus |
|
From: Per W. <pw...@ia...> - 2003-04-02 23:33:54
|
Just for the fun of it, I tested the previous code you sent.
One million calls (i=0..999999) resulted in:
Ioannis with malloc itoa(int) 4536 ms
Ioannis with auto-buf itoa(int,char*) 661 ms
itoa using sprintf and auto-buf itoa(int,char*) 1512 ms
DevStudio built-in and auto-buf _itoa(int,char*,int) 481 ms
The malloc()/free() code took 6.9 times longer than if the buffer was sent
in as a parameter - both alternatives are threadsafe. 85% of the runtime
time was malloc()/free().
That's why I try and keep an eye on heap allocations, and try for stack
buffers or buffer pools.
/Per W
On Thu, 3 Apr 2003, Ioannis Vranos wrote:
> Ok, in order to be complete (with what I consider as an itoa() without any
> specific constraint requirements) I repost a complete itoa(), with the few
> bugs fixed. The implementation was influenced by the spirit "(Real
> programmers) Don't comment their code. If it was hard to write, it should be
> hard to
> understand and even harder to modify." See the attached file.
>
>
> #include <stddef.h>
> #include <stdlib.h>
> #include <stdio.h>
>
>
> char *itoa(int i)
> {
> size_t Length;
> char *p;
> int temp=i;
>
> int sign=temp<0?-1:1;
>
> if(!sign)
> {
> p=malloc(2);
>
> if(!p)
> return NULL;
>
> p[0]='0', p[1]=0;
>
> return p;
> }
>
> temp=sign*i;
>
> for(Length=0; temp/=10; Length++)
> ;
>
> p=malloc(Length+1+!sign==1);
>
> if(!p)
> return NULL;
>
> sprintf(p, "%d", i);
>
> return p;
> }
>
>
>
> Ioannis Vranos
>
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL: http://run.to/noicys
>
|
|
From: Ioannis V. <iv...@em...> - 2003-04-02 22:56:31
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...]=20 > Sent: Thursday, April 03, 2003 2:42 AM > To: Ioannis Vranos > Cc: 'Dev-C++' > Subject: RE: [Dev-C++] itoa - atoi : another implementation=20 >=20 >=20 > I just tried to say that a itoa() with memory allocation is not of > much value. It consumes a lot of CPU-time in allocation/release, it > requires extra clean-up code, and a failure to clean will=20 > result in memory > leaks. Yes, if we are not good coders we can't depend on the library to do our work. The library is responsible for its work only, and if it fails it signals failure in case we know how to handle the problem or to abort = under control. So "don't use memory on the free store because the user needs clean up = code and may have memory leaks" is not a problem of the library coder. Regarding time cost, I prefer thread safety to time cost. If time cost = of malloc()/free() is considered huge you can provide a special itoa() or = work with a default parameter in C++ which would be nice. char *itoa(int number, char *buffer=3D0); For usual systems I would use an std::string. > A itoa(int,char*[,int]) may even be used in a ISR with a deterministic > behaviour, i.e. the answer will always be available in a fixed maximum > time (with a fixed maximum stack use), and there is no way any running > task may have locked a mutex. Code using malloc()/free() are extremely > vulnerable for mutex locks. Good implementations of sprintf() is Sorry, I have no idea what mutex locks are (and I don't want to bother = to searh in google, my current priority are PCs). > mutex-free, but most of the time the supplier doesn't specify=20 > it in the > documentation, so you don't know. >=20 > Never any intention of embarrassing anyone. To make you=20 > really happy, I > just noticed something really embarrasing. The ltoa()=20 > implementation for > the RTOS I'm using will fail for a radix < 10 because the guy=20 > implementing > it forgot that a smaller radix requires a bigger buffer. The=20 > code assumes > wort-case buffer use for radix 10... >=20 > I always consider dynamic heap usage as expensive. Because you work for microcontrollers. On the other hand my major = concern is .NET. :) > It's=20 > (almost) always ok > in bread-and-butter programs but in drivers, servers, embedded > environments and where the cude must support very long uptime=20 > with high > memory utilization (constantly being close to the limit of available > memory where heap fragmentation gets extra dangerous) great care is > needed. I understand. Well if you do bare metal programming you cann allocate = the entire free store and use it in a defragmented way (=3Dtime cost). But = if you do not use the free store, all that memory will go useless? The best approach is use memory on the free store and if it gets too fragmented = use the automatic storage/stack. C++ provides the ability to define the "placement operator new" which is very nice since you can program it to use the stack instead of the heap = or a combination of them! =20 > A NIC driver that allocates all packets when they arrive=20 > might easily get > half transfer speed compared to a driver using a packet pool.=20 > This is a > bit of problem with object-oriented languages, since extra=20 > allocations are > so easily hidden somewhere in a base class=20 > constructor/destructor etc, and > if you don't know what speed you should expect from your=20 > code, you don't > notice the hidden slowdown. OK. Ioannis Vranos =20 * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Per W. <pw...@ia...> - 2003-04-02 22:42:57
|
See below. /Per W On Thu, 3 Apr 2003, Ioannis Vranos wrote: > > -----Original Message----- > > From: Per Westermark [mailto:pw...@ia...] > > Sent: Thursday, April 03, 2003 1:34 AM > > To: Ioannis Vranos > > Cc: 'Dev-C++' > > Subject: RE: [Dev-C++] itoa - atoi : another implementation > > > > In a lot of embedded environments, itoa() is king, because of that. If > > a microcontroller have 8kB program area, itoa() consumes 100 byte and > > sprintf() consumes 2kB, the choice is quite easy. > > > My itoa() was not intended for a microcontroler. > > > > > > The above is not thread safe (since as I saw you try to > > embarrass me). :) > > > You must place a locking mechanism. > > > > That's why most implementations of itoa takes a buffer as second > > parameter. > > > But you said: I just tried to say that a itoa() with memory allocation is not of much value. It consumes a lot of CPU-time in allocation/release, it requires extra clean-up code, and a failure to clean will result in memory leaks. A itoa(int,char*[,int]) may even be used in a ISR with a deterministic behaviour, i.e. the answer will always be available in a fixed maximum time (with a fixed maximum stack use), and there is no way any running task may have locked a mutex. Code using malloc()/free() are extremely vulnerable for mutex locks. Good implementations of sprintf() is mutex-free, but most of the time the supplier doesn't specify it in the documentation, so you don't know. > > > > It isn't even a good optimization of number of source code > > > characters, since each call MUST be either: > > > free(itoa(i1)); > > > which is an expensive NOP instruction, or: > > > Decide if you consider the free store usage expensive or not. In any case > there wan't any requirement for microcontrollers. In any case you try > intentionally to embarrass me. :) Never any intention of embarrassing anyone. To make you really happy, I just noticed something really embarrasing. The ltoa() implementation for the RTOS I'm using will fail for a radix < 10 because the guy implementing it forgot that a smaller radix requires a bigger buffer. The code assumes wort-case buffer use for radix 10... I always consider dynamic heap usage as expensive. It's (almost) always ok in bread-and-butter programs but in drivers, servers, embedded environments and where the cude must support very long uptime with high memory utilization (constantly being close to the limit of available memory where heap fragmentation gets extra dangerous) great care is needed. A NIC driver that allocates all packets when they arrive might easily get half transfer speed compared to a driver using a packet pool. This is a bit of problem with object-oriented languages, since extra allocations are so easily hidden somewhere in a base class constructor/destructor etc, and if you don't know what speed you should expect from your code, you don't notice the hidden slowdown. > > > > www.uclibc.org (Small open clib for embedded systems) > > char *itoa(int i); > > note: uses static buffer > > > That's nice, mine uses the free store, is thread safe and is intended for > systems which can afford 8 kbs space cost. > It isn't uncommon that sprintf() uses a itoa(int,char*,int) (or ltoa) to implement the %d support. I just checked on a RTOS I'm using and noticed that their ltoa() would fail for a radix < 10 because of too small > > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: ValueWeb: > Dedicated Hosting for just $79/mo with 500 GB of bandwidth! > No other company gives more support or power for your dedicated server > http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Ioannis V. <iv...@em...> - 2003-04-02 22:36:14
|
I decided to take the subject a bit more seriuosly and ended with the
following:
#include <stdlib.h>
#include <stdio.h>
char *iitoa(int i)
{
long Length, j;
char *p;
char numchars[]="0123456789";
int temp=i;
int sign=temp<0?-1:1;
if(!temp)
{
p=malloc(2);
if(!p)
return NULL;
p[0]='0', p[1]=0;
return p;
}
for(Length=1; temp/=10; Length++)
;
p=malloc(Length+=1+(sign==-1));
if(!p)
return NULL;
if(sign==-1)
p[0]='-';
p[Length-1]=0;
for(temp=i*sign, j=Length-2; j>=(sign==1?0:1); j--)
{
p[j]=numchars[temp%10];
temp/=10;
}
return p;
}
It doesn't convert to any other number base, it produces only in decimal.
My apologies for the many emails.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|
|
From: JOSE L. G. G. <jl...@us...> - 2003-04-02 21:51:25
|
=BFSi alguien es tan amable de explicarme como puedo pasar programas = escritos en Borland 3.1, especialmente gr=E1ficos, al entorno Dev-C++. Gracias. |
|
From: Ioannis V. <iv...@em...> - 2003-04-02 21:46:55
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Thursday, April 03, 2003 1:34 AM > To: Ioannis Vranos > Cc: 'Dev-C++' > Subject: RE: [Dev-C++] itoa - atoi : another implementation > > In a lot of embedded environments, itoa() is king, because of that. If > a microcontroller have 8kB program area, itoa() consumes 100 byte and > sprintf() consumes 2kB, the choice is quite easy. My itoa() was not intended for a microcontroler. > > The above is not thread safe (since as I saw you try to > embarrass me). :) > > You must place a locking mechanism. > > That's why most implementations of itoa takes a buffer as second > parameter. But you said: > > It isn't even a good optimization of number of source code > > characters, since each call MUST be either: > > free(itoa(i1)); > > which is an expensive NOP instruction, or: Decide if you consider the free store usage expensive or not. In any case there wan't any requirement for microcontrollers. In any case you try intentionally to embarrass me. :) > www.uclibc.org (Small open clib for embedded systems) > char *itoa(int i); > note: uses static buffer That's nice, mine uses the free store, is thread safe and is intended for systems which can afford 8 kbs space cost. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Per W. <pw...@ia...> - 2003-04-02 21:34:46
|
See below. /Per W On Wed, 2 Apr 2003, Ioannis Vranos wrote: > > -----Original Message----- > > From: Per Westermark [mailto:pw...@ia...] > > Sent: Wednesday, April 02, 2003 10:13 PM > > To: Ioannis Vranos > > Cc: 'Dev-C++' > > Subject: RE: [Dev-C++] itoa - atoi : another implementation > > > > > > You might have been in even more hurry :-) > > > > How many characters do you allocate if the integer was zero, > > or negative? > > > > Yes you are right, I forgot the <=0 stuff. Well I leave it as an exercise > for home. :) > > > > > > > And then of course - itoa() with a sprintf() is of very > > little use, since > > it doesn't solve reentrancy problems, > > > What do you mean. > All environments doesn't have a reentrant sprintf() that you might call from an ISR. > > > > doesn't support variable number > > base, > > > No it doesn't. > > > > and doesn't allow linking without the formatted RTL code. > > > What do you mean. The implementation of sprintf() is normally very large. On an environment that links clib static, check size of binary with use of itoa() with static allocation or buffer as input param and compare it with sprintf() and you'll see the difference. In a lot of embedded environments, itoa() is king, because of that. If a microcontroller have 8kB program area, itoa() consumes 100 byte and sprintf() consumes 2kB, the choice is quite easy. > > > > > It isn't even a good optimization of number of source code > > characters, since each call MUST be either: > > free(itoa(i1)); > > which is an expensive NOP instruction, or: > > > It is supposed to be used where free store usage is affordable (almost > everywhere these days). No specific constraint requirements were provided by > the OP. > > > > > char *p = itoa(i1); > > use_string(p); > > free(p); > > which isn't much shorter than > > char buf[20]; > > sprintf(buf,"%d",i1); > > use_string(buf); > > > > Yes it isn't. That's why I said itoa() is not needed. > > > > > > Whith a static buffer in itoa() you get code length improvement > > with: > > use_string(itoa(i1)); > > > The above is not thread safe (since as I saw you try to embarrass me). :) > You must place a locking mechanism. That's why most implementations of itoa takes a buffer as second parameter. > > > > and with a semi-standard implementation of itoa you get code length > > improvement AND extra number bases: > > char buf[30]; > > use_string(itoa(i1,buf,3)); // trinary output > > > I do not know any standard or semi-standard impleentation of itoa(). Even in > K&R2 it is not what you are talking about. A number of impelemntations of itoa: Developer Studio: char *_itoa(int value, char *string, int radix); note: M$ adds the leading _ on a lot of functions, such as _open(), _getcwd(), ... QNX (www.qnx.com): char* itoa(int value, char* buffer, int radix); www.cplusplus.com/ref/cstdlib/itoa.html: char* itoa(int value,char* buffer,int radix); have note: Not defined in ANSI-C. Supported by some compilers. http://developer.novell.com/ndk/doc/libc/index.html?page=/ndk/doc/libc/libc_enu/data/sdk959.html char *itoa(int value,char *buffer,int radix); note: They classifies it as ANSI www.uclibc.org (Small open clib for embedded systems) char *itoa(int i); note: uses static buffer > > > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: ValueWeb: > Dedicated Hosting for just $79/mo with 500 GB of bandwidth! > No other company gives more support or power for your dedicated server > http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Ioannis V. <iv...@em...> - 2003-04-02 21:23:37
|
^%^%%^*@#@# a bug had survived. The good & last:
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
char *itoa(int i)
{
size_t Length;
char *p;
int temp=i;
int sign=temp<0?-1:1;
if(!temp)
{
p=malloc(2);
if(!p)
return NULL;
p[0]='0', p[1]=0;
return p;
}
temp*=sign;
for(Length=0; temp/=10; Length++)
;
p=malloc(Length+1+!(sign==1));
if(!p)
return NULL;
sprintf(p, "%d", i);
return p;
}
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|
|
From: Ioannis V. <iv...@em...> - 2003-04-02 21:19:49
|
Ok, in order to be complete (with what I consider as an itoa() without =
any
specific constraint requirements) I repost a complete itoa(), with the =
few
bugs fixed. The implementation was influenced by the spirit "(Real
programmers) Don't comment their code. If it was hard to write, it =
should be
hard to
understand and even harder to modify." See the attached file.
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
char *itoa(int i)
{
size_t Length;
char *p;
int temp=3Di;
=20
int sign=3Dtemp<0?-1:1;
=20
if(!sign)
{
p=3Dmalloc(2);
=09
if(!p)
return NULL;
=20
p[0]=3D'0', p[1]=3D0;
return p;
}
=20
temp=3Dsign*i;
for(Length=3D0; temp/=3D10; Length++)
;
p=3Dmalloc(Length+1+!sign=3D=3D1);
if(!p)
return NULL;
sprintf(p, "%d", i);
=20
return p;
}
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|
|
From: Ioannis V. <iv...@em...> - 2003-04-02 20:55:03
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...]=20 > Sent: Wednesday, April 02, 2003 10:13 PM > To: Ioannis Vranos > Cc: 'Dev-C++' > Subject: RE: [Dev-C++] itoa - atoi : another implementation=20 >=20 >=20 > You might have been in even more hurry :-) >=20 > How many characters do you allocate if the integer was zero,=20 > or negative? Yes you are right, I forgot the <=3D0 stuff. Well I leave it as an = exercise for home. :) >=20 > And then of course - itoa() with a sprintf() is of very=20 > little use, since > it doesn't solve reentrancy problems, What do you mean. > doesn't support variable number > base, No it doesn't. > and doesn't allow linking without the formatted RTL code. What do you mean. =20 > It isn't even a good optimization of number of source code > characters, since each call MUST be either: > free(itoa(i1)); > which is an expensive NOP instruction, or: It is supposed to be used where free store usage is affordable (almost everywhere these days). No specific constraint requirements were = provided by the OP. > char *p =3D itoa(i1); > use_string(p); > free(p); > which isn't much shorter than > char buf[20]; > sprintf(buf,"%d",i1); > use_string(buf); Yes it isn't. That's why I said itoa() is not needed. =20 > Whith a static buffer in itoa() you get code length improvement > with: > use_string(itoa(i1)); The above is not thread safe (since as I saw you try to embarrass me). = :) You must place a locking mechanism. > and with a semi-standard implementation of itoa you get code length > improvement AND extra number bases: > char buf[30]; > use_string(itoa(i1,buf,3)); // trinary output I do not know any standard or semi-standard impleentation of itoa(). = Even in K&R2 it is not what you are talking about. Ioannis Vranos =20 * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Ioannis V. <iv...@em...> - 2003-04-02 20:46:25
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...]=20 > Sent: Wednesday, April 02, 2003 9:44 PM > To: Ioannis Vranos > Cc: 'Dev-C++' > Subject: RE: [Dev-C++] itoa - atoi : another implementation=20 >=20 >=20 > The most common is one of the following declarations: > void itoa(int num, char *buf, int base); > void itoa(int num, char *buf); >=20 > Neither have problem with lost memory, and both are reentrant. >=20 > The first form is always useful, since it allows adjustable=20 > number base, > i.e. binary, trinary, ... I had written some time ago an unsigned to string conversion function in = any number system. But after some time I erased it because except of = hexadecimal and octadecimal systems, it is very rare to use trinary etc in a = program. And for hex and oct we can do the job with the printf() family. > The second form is only needed in embedded programs, since it requires > less RTL support than the big-big-big sprintf() - note that sprintf() > doesn't know whet additional support that is required, so it=20 > has code for > left-adjust, right-adjust, int, long, signed, unsigned,=20 > string, pointer, > float, double, ... I haven't played with embedded systems, but for usual ones I consider = the horsepower/memory enough so as to have the entire C90. I think that if a system can't hold C90, it can only be programmed with assembly. Memory = is very cheap these days. For example one could place an intel processor = with 1 mb ram easily in an embedded system (e.g. just a 286 or some of the = intel processors used for palmtops etc, or from other companies). Ioannis Vranos =20 * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Per W. <pw...@ia...> - 2003-04-02 18:27:04
|
I don't know if there is a directly callable API for the information.If
you program COM, there is an interface
IDiskQuotaUser::GetQuotaInformation
that will give the info.
/Per W
On Wed, 2 Apr 2003, Hammamur Rahman wrote:
> H, I've used the the function below succesfully, but one the thing it does
> not allow you to get is the number of bythes availabe to the calling user
> (i.e the allocated quota for that user), it only allows to retrieve the
> total number of free bytes on the disk that are available to the user.
>
> BOOL GetDiskFreeSpaceEx(
> LPCTSTR lpDirectoryName,
> PULARGE_INTEGER lpFreeBytesAvailable,
> PULARGE_INTEGER lpTotalNumberOfBytes,
> PULARGE_INTEGER lpTotalNumberOfFreeBytes
> );
>
> Is the another function which can obtain this.
>
> Thank you!
>
>
> _________________________________________________________________
> Surf together with new Shared Browsing
> http://join.msn.com/?page=features/browse&pgmarket=en-gb&XAPID=74&DI=1059
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Per W. <pw...@ia...> - 2003-04-02 18:14:38
|
You might have been in even more hurry :-)
How many characters do you allocate if the integer was zero, or negative?
And then of course - itoa() with a sprintf() is of very little use, since
it doesn't solve reentrancy problems, doesn't support variable number
base, and doesn't allow linking without the formatted RTL code.
It isn't even a good optimization of number of source code
characters, since each call MUST be either:
free(itoa(i1));
which is an expensive NOP instruction, or:
char *p = itoa(i1);
use_string(p);
free(p);
which isn't much shorter than
char buf[20];
sprintf(buf,"%d",i1);
use_string(buf);
Whith a static buffer in itoa() you get code length improvement
with:
use_string(itoa(i1));
and with a semi-standard implementation of itoa you get code length
improvement AND extra number bases:
char buf[30];
use_string(itoa(i1,buf,3)); // trinary output
/Per W
On Wed, 2 Apr 2003, Ioannis Vranos wrote:
> In my hurry I forgot the basics:
>
>
>
> > -----Original Message-----
> > From: dev...@li...
> > [mailto:dev...@li...] On Behalf
> > Of Ioannis Vranos
> > Sent: Wednesday, April 02, 2003 2:46 PM
> > To: 'Dev-C++'
> > Subject: RE: [Dev-C++] itoa - atoi : another implementation
> >
> >
> > My own contribution to this entirely unneded function:
> >
> > #include <stddef.h>
> > #include <stdlib.h>
> > #include <stdio.h>
> >
> >
> > char *itoa(int i)
> > {
> > size_t Length;
> > char *p;
> > int temp=i;
> >
> > for(Length=0; temp/=10; Length++)
> > ;
> >
> > p=malloc((Length+1)*sizeof(i));
>
> if(!p)
> return NULL;
>
>
> >
> > sprintf(p, "%d", i);
> >
> > return p;
> > }
> >
> >
> >
> > Why would anyone need itoa()? With sprinf() one can easily do the
> > conversion.
> >
> >
> > sprintf(s,"%d", i);
> >
> >
> > Ioannis Vranos
> >
> > * Programming pages: http://www.noicys.freeurl.com
> > * Alternative URL: http://run.to/noicys
>
> >
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Per W. <pw...@ia...> - 2003-04-02 18:12:24
|
It takes less code - and is faster - to count needed buffer space and
insert backwards than to have to flip at the end.
One more thing. Why call j=3Dstrlen(s)-1 in the last loop, when you already
know how many characters you have inserted in the string?
/Per W
On Wed, 2 Apr 2003, Ricardo L=F3pez Ruiz wrote:
> If you are interested in another implementation
> of itoa( ) and atoi ( ), here you have the code.
> Hope it can be helpful.
> Ricardo.
>
>
> **************ITOA( ) ******************
> /* ITOA: Transforms the long n to a string s */
> #include <stdio.h>
> #include <string.h>
> main( )
> {
> char s[500];
> long int n,sign;
> int i,j,c;
>
> printf("give me a number to convert:\n");
> scanf("%ld",&n);
> if((sign=3Dn)<0) /* changing the sign of a negative number */
> n=3D-n;
>
> i=3D0; /* obtaining the digits of the number */
> do{
> s[i++]=3Dn%10 + '0';
> }while((n/=3D10)>0);
>
> if(sign<0) /* returning the correct sign */
> s[i++]=3D'-';
> s[i]=3D'\0'; /* end of the string */
>
> /* reverse (s) */
> for(i=3D0,j=3Dstrlen(s)-1 ;i<j ; i++,j--)
> {
> c=3Ds[i];
> s[i]=3Ds[j];
> s[j]=3Dc;
> }
>
> printf("the result is:\n%s\n",s);
> printf("FIN\n");
> system("PAUSE");
> return 0;
> }
> ************************************
>
> ***************** ATOI( ) ***************
> /* ATOI: Reading a number as a string s and returning it as a number n */
>
> #include <stdio.h>
> main( )
> {
> char s[100];
> long int n; int i;
>
> printf("give a number chain: \n");
> gets(s);
> printf("your number chain is: %s\n",s);
>
> n=3D0; /* tranforming s to a number n */
> for(i=3D0;s[i]>=3D'0' && s[i]<=3D'9'; ++i)
> n=3Dn*10+(s[i]-'0');
>
> printf("the number is: %ld\n number of digits: %d\n",n,i);
> printf("FIN\n");
> system("PAUSE");
> return 0;
> }
> ************************************
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Per W. <pw...@ia...> - 2003-04-02 18:10:37
|
For a itoa() that returns a pointer, you normally want it defined similar
to asctime(), ctime(), gmtime(), localtime(), ...
If you then need multiple calls before doing something else, you may then
always do:
strcpy(buf1,itoa(i1));
strcpy(buf2,itoa(i2));
...
A dynamically allocating itoa() would be very hard to use in an efficient
way without memory leaks.
You normally don't need to call itoa multiple times before using the
results, since the majority use of itoa() is for output, and if you
have printf(), the following code is meaningless:
char *p1 = itoa(i1), *p2 = itoa(i2);
printf("The result was %s and %s\n",p1,p2);
itoa() is often used in embedded systems where you might not have room
for printf(), and then your output function doesn't support variable
arguments, i.e. you have to do something like:
send(COM1,"The result was ");
send(COM1,itoa(i1));
send(COM1," and ");
send(COM1,itoa(i2));
send(COM1,"\n");
However, the normal implementation of itoa() is with a pointer to buffer
as the second parameter, and possible a number base as third parameter.
Then you have the best of two worlds. Reentrant, quick, non-leaking, ...
/Per W
On Wed, 2 Apr 2003, Ioannis Vranos wrote:
> > -----Original Message-----
> > From: dev...@li...
> > [mailto:dev...@li...] On Behalf
> > Of Luigi Santillo
> > Sent: Wednesday, April 02, 2003 9:01 AM
> > To: dev...@li...
> > Subject: [Dev-C++] itoa - simple implementation [was: integer
> > to string]
> >
> >
> > On Wed, Apr 02, 2003 at 04:38:41AM +0200, Per Westermark wrote:
> > > Assign of string termination will be one position off, i.e.
> > outside your
> > > buffer.
> > > [..]
> >
> > Thanks again for pointing out the bug, I'll fix it as shown by the
> > few code lines below.
> >
> > One thing I was wondering is: since "buf" is static, may I assume
> > it is filled with '\0' by the compiler? (So there will be ne need
> > for me to place the terminating '\0')
> >
> >
> > itoa.c
> > ------
> > /* .. */
> >
> > /* old code: #define MAXSZ 21 */
> > #define MAXSZ 20 /* assuming integer is made of 19 digits + sign */
> >
> > char *
> > itoa(int n)
> > {
> > /* old code: static char buf[MAXSZ]; */
> > static char buf[MAXSZ + 1];
> > char *p = buf + MAXSZ;
> > /* ... */
> > *p = '\0'; /* << really needed ? >> */
> > }
>
>
> This code is not good. Assume this:
>
>
> char *p=itoa(9), *q=itoa(10);
>
>
> I suggest to return a pointer on memory on the free store.
>
>
>
>
> Ioannis Vranos
>
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL: http://run.to/noicys
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Per W. <pw...@ia...> - 2003-04-02 17:45:17
|
The most common is one of the following declarations:
void itoa(int num, char *buf, int base);
void itoa(int num, char *buf);
Neither have problem with lost memory, and both are reentrant.
The first form is always useful, since it allows adjustable number base,
i.e. binary, trinary, ...
The second form is only needed in embedded programs, since it requires
less RTL support than the big-big-big sprintf() - note that sprintf()
doesn't know whet additional support that is required, so it has code for
left-adjust, right-adjust, int, long, signed, unsigned, string, pointer,
float, double, ...
/Per W
On Wed, 2 Apr 2003, Ioannis Vranos wrote:
> My own contribution to this entirely unneded function:
>
> #include <stddef.h>
> #include <stdlib.h>
> #include <stdio.h>
>
>
> char *itoa(int i)
> {
> size_t Length;
> char *p;
> int temp=i;
>
> for(Length=0; temp/=10; Length++)
> ;
>
> p=malloc((Length+1)*sizeof(i));
>
> sprintf(p, "%d", i);
>
> return p;
> }
>
>
>
> Why would anyone need itoa()? With sprinf() one can easily do the
> conversion.
>
>
> sprintf(s,"%d", i);
>
>
> Ioannis Vranos
>
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL: http://run.to/noicys
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Per W. <pw...@ia...> - 2003-04-02 17:35:48
|
Yes, global variables and static variables are always zero-filled on
startup, so in this case, you could skip the terminating zero.
/Per W
On Wed, 2 Apr 2003, Luigi Santillo wrote:
> On Wed, Apr 02, 2003 at 04:38:41AM +0200, Per Westermark wrote:
> > Assign of string termination will be one position off, i.e. outside your
> > buffer.
> > [..]
>
> Thanks again for pointing out the bug, I'll fix it as shown by the
> few code lines below.
>
> One thing I was wondering is: since "buf" is static, may I assume
> it is filled with '\0' by the compiler? (So there will be ne need
> for me to place the terminating '\0')
>
>
> itoa.c
> ------
> /* .. */
>
> /* old code: #define MAXSZ 21 */
> #define MAXSZ 20 /* assuming integer is made of 19 digits + sign */
>
> char *
> itoa(int n)
> {
> /* old code: static char buf[MAXSZ]; */
> static char buf[MAXSZ + 1];
> char *p = buf + MAXSZ;
> /* ... */
> *p = '\0'; /* << really needed ? >> */
> }
> ------
>
> Regards
> --
> >> gisan >>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Hammamur R. <hra...@ho...> - 2003-04-02 16:33:45
|
H, I've used the the function below succesfully, but one the thing it does not allow you to get is the number of bythes availabe to the calling user (i.e the allocated quota for that user), it only allows to retrieve the total number of free bytes on the disk that are available to the user. BOOL GetDiskFreeSpaceEx( LPCTSTR lpDirectoryName, PULARGE_INTEGER lpFreeBytesAvailable, PULARGE_INTEGER lpTotalNumberOfBytes, PULARGE_INTEGER lpTotalNumberOfFreeBytes ); Is the another function which can obtain this. Thank you! _________________________________________________________________ Surf together with new Shared Browsing http://join.msn.com/?page=features/browse&pgmarket=en-gb&XAPID=74&DI=1059 |
|
From: Marco N. <th...@ti...> - 2003-04-02 15:58:44
|
You can use a MAPI function called MAPISendMail to send mail with your
default profile in your default email client (ie Outlook Express). Remember
to link mapi32.dll to your project (-lmapi32 in linker options).
#include <windows.h>
#include <mapi.h>
int main (int argc, char **argv) {
MapiMessage Mex;
MapiRecipDesc To;
ULONG res;
To.ulReserved=0;
To.ulRecipClass=MAPI_TO;
To.lpszName = (LPTSTR) GlobalAlloc (GPTR, 100);
lstrcpy (To.lpszName, "Someone");
To.lpszAddress = (LPTSTR) GlobalAlloc (GPTR, 100);
lstrcpy (To.lpszAddress, "so...@so...");
To.ulEIDSize=0;
To.lpEntryID=NULL;
Mex.ulReserved=0;
Mex.lpszSubject = (LPTSTR) GlobalAlloc (GPTR, 100);
lstrcpy (Mex.lpszSubject, "Hello world!");
Mex.lpszNoteText = (LPTSTR) GlobalAlloc (GPTR, 100);
lstrcpy (Mex.lpszNoteText, "This is an e-mail.\n");
Mex.lpszMessageType = NULL;
Mex.lpszDateReceived = NULL;
Mex.lpszConversationID = NULL;
Mex.flFlags = 0;
Mex.lpOriginator = NULL;
Mex.nRecipCount = 1;
Mex.lpRecips = &To;
Mex.nFileCount = 0;
Mex.lpFiles = NULL;
res=MAPISendMail (0, 0, &Mex, MAPI_NEW_SESSION, 0);
return 0;
}
|
|
From: Muhammad F. <fa...@cy...> - 2003-04-02 14:13:38
|
Hi, I want to make an application to send email. Please guide me to make such an application and tell me which API/s will be used. Regards Farhan |