Thread: Re: [Dev-C++] Crash with macro to template conversion
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: David M. <ci...@ya...> - 2004-02-28 06:06:24
|
Sorry about that the correct definition is:
template<class T>
void create(T * ptr, int number, char * f_name = __FILE__, int l_num
=
__LINE__)
{
ptr = new T[number];
if ( !ptr )
{
perror("malloc failure");
fprintf( stderr, "Malloc failure @ %s:%d\n", f_name, l_num );
abort();
}
}
All the exception stuff was just trying to figure out if an error is
even
occuring.
I am trying to keep to convention. The macro is not my code but code
I am
trying to replace. I am very tempted to change it but I also have
RECREATE
(wraps realloc()) and DESTROY (wraps free() ) which also need to be
replaced. I could use macros to alter the function call but I am
trying to
remove all the macros I can (got some linked list macros to replace
as well)
So...How does one create a refrence to a pointer?
----- Original Message -----
From: "Per Westermark" <pw...@ia...>
To: "David McKen" <ci...@ya...>
Cc: "Mailing List, Dev-Cpp" <dev...@li...>
Sent: Friday, February 27, 2004 7:08 AM
Subject: Re: [Dev-C++] Crash with macro to template conversion
> First of all - your create template function is declared to return
void,
> so why do you end it with return ptr?
>
> Second, you send in a T* ptr parameter. Note that since C++ uses
> call-by-value, this will behave like a lokal variable, i.e any
assign to
> ptr will not reflect back to the caller. You should change the
first
> parameter of create to be a reference to a pointer. That way, the
assign
> to ptr will reflect back to the variable obj of the caller.
>
> /Per W
>
> On Fri, 27 Feb 2004, David McKen wrote:
>
> > Ok here is my problem.
> >
> > I want to replace:
> > #define CREATE(result, type, number) \
> > do \
> > { \
> > if (!((result) = (type *) calloc ((number), sizeof(type)))) \
> > { \
> > perror("malloc failure"); \
> > fprintf(stderr, "Malloc failure @ %s:%d\n", __FILE__,
__LINE__ );
> > \
> > abort(); \
> > } \
> > } while(0)
> >
> > With it's C++ equivalent.
> >
> > So far I have:
> > #define CREATE(result, type, num) create<type>((result),(num))
> > template<class T>
> > void create(T * ptr, int number, char * f_name = __FILE__, int
l_num
> > =
> > __LINE__)
> > {
> > try {
> > ptr = new T[number];
> > }
> > catch(bad_alloc& b)
> > {
> > perror("malloc failure");
> > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name, l_num );
> > abort();
> > }
> > if ( !ptr )
> > {
> > perror("malloc failure");
> > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name, l_num );
> > abort();
> > }
> > return ptr;
> > }
> >
> > But the program crashes after the function call when any attempt
to
> > acces
> > the data occours:
> > e.g.
> > OBJ_DATA * obj;
> > CREATE( obj , OBJ_DATA, 1 );
> >
> > obj->some_field = 5; //Crashes here and obj = 0x0 from gdb.
> >
> > Thanks in Advance
> > David McKen
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > Get better spam protection with Yahoo! Mail.
> > http://antispam.yahoo.com/tools
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
__________________________________
Do you Yahoo!?
Get better spam protection with Yahoo! Mail.
http://antispam.yahoo.com/tools
|
|
From: David M. <ci...@ya...> - 2004-02-28 23:22:11
|
you apparently did not read the end of my message,
I know how to create a pointer to a pointer (**) I haven't heard
about a
refrence to a pointer (&* ?), what is the syntax for such a variable?
----- Original Message -----
From: "Per Westermark" <pw...@ia...>
To: "David McKen" <ci...@ya...>
Cc: "Mailing List, Dev-Cpp" <dev...@li...>
Sent: Saturday, February 28, 2004 5:27 AM
Subject: Re: [Dev-C++] Crash with macro to template conversion
> But you have not fixed the declaration of the ptr parameter yet.
Any
> allocations you make will behave ok inside the create() function,
but the
> caller will never get the value of the allocated pointer! You
REALLY MUST
> change del parameter declaration to either be a pointer to a
pointer, or a
> reference to a pointer!
>
> /Per W
>
> On Fri, 27 Feb 2004, David McKen wrote:
>
> > Sorry about that the correct definition is:
> > template<class T>
> > void create(T * ptr, int number, char * f_name = __FILE__, int
l_num
> > =
> > __LINE__)
> > {
> > ptr = new T[number];
> > if ( !ptr )
> > {
> > perror("malloc failure");
> > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name, l_num );
> > abort();
> > }
> > }
> >
> > All the exception stuff was just trying to figure out if an error
is
> > even
> > occuring.
> >
> > I am trying to keep to convention. The macro is not my code but
code
> > I am
> > trying to replace. I am very tempted to change it but I also have
> > RECREATE
> > (wraps realloc()) and DESTROY (wraps free() ) which also need to
be
> > replaced. I could use macros to alter the function call but I am
> > trying to
> > remove all the macros I can (got some linked list macros to
replace
> > as well)
> >
> > So...How does one create a refrence to a pointer?
> >
> > ----- Original Message -----
> > From: "Per Westermark" <pw...@ia...>
> > To: "David McKen" <ci...@ya...>
> > Cc: "Mailing List, Dev-Cpp" <dev...@li...>
> > Sent: Friday, February 27, 2004 7:08 AM
> > Subject: Re: [Dev-C++] Crash with macro to template conversion
> >
> >
> > > First of all - your create template function is declared to
return
> > void,
> > > so why do you end it with return ptr?
> > >
> > > Second, you send in a T* ptr parameter. Note that since C++
uses
> > > call-by-value, this will behave like a lokal variable, i.e any
> > assign to
> > > ptr will not reflect back to the caller. You should change the
> > first
> > > parameter of create to be a reference to a pointer. That way,
the
> > assign
> > > to ptr will reflect back to the variable obj of the caller.
> > >
> > > /Per W
> > >
> > > On Fri, 27 Feb 2004, David McKen wrote:
> > >
> > > > Ok here is my problem.
> > > >
> > > > I want to replace:
> > > > #define CREATE(result, type, number) \
> > > > do \
> > > > { \
> > > > if (!((result) = (type *) calloc ((number),
sizeof(type)))) \
> > > > { \
> > > > perror("malloc failure"); \
> > > > fprintf(stderr, "Malloc failure @ %s:%d\n", __FILE__,
> > __LINE__ );
> > > > \
> > > > abort(); \
> > > > } \
> > > > } while(0)
> > > >
> > > > With it's C++ equivalent.
> > > >
> > > > So far I have:
> > > > #define CREATE(result, type, num)
create<type>((result),(num))
> > > > template<class T>
> > > > void create(T * ptr, int number, char * f_name = __FILE__,
int
> > l_num
> > > > =
> > > > __LINE__)
> > > > {
> > > > try {
> > > > ptr = new T[number];
> > > > }
> > > > catch(bad_alloc& b)
> > > > {
> > > > perror("malloc failure");
> > > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name,
l_num );
> > > > abort();
> > > > }
> > > > if ( !ptr )
> > > > {
> > > > perror("malloc failure");
> > > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name,
l_num );
> > > > abort();
> > > > }
> > > > return ptr;
> > > > }
> > > >
> > > > But the program crashes after the function call when any
attempt
> > to
> > > > acces
> > > > the data occours:
> > > > e.g.
> > > > OBJ_DATA * obj;
> > > > CREATE( obj , OBJ_DATA, 1 );
> > > >
> > > > obj->some_field = 5; //Crashes here and obj = 0x0 from gdb.
> > > >
> > > > Thanks in Advance
> > > > David McKen
> > > >
> > > >
> > > > __________________________________
> > > > Do you Yahoo!?
> > > > Get better spam protection with Yahoo! Mail.
> > > > http://antispam.yahoo.com/tools
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > Build and deploy apps & Web services for Linux with
> > > > a free DVD software kit from IBM. Click Now!
> > > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > > _______________________________________________
> > > > Dev-cpp-users mailing list
> > > > Dev...@li...
> > > > TO UNSUBSCRIBE:
http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > >
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > Get better spam protection with Yahoo! Mail.
> > http://antispam.yahoo.com/tools
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
__________________________________
Do you Yahoo!?
Get better spam protection with Yahoo! Mail.
http://antispam.yahoo.com/tools
|
|
From: Per W. <pw...@ia...> - 2004-02-28 23:31:33
|
Oops. Too quick answer :-)
With the following construct, the caller will get back the newly allocated
pointer:
void alloc(char*& ptr) {
ptr = new char[10];
}
int main() {
char *ptr = NULL;
printf("ptr = %p\n",ptr);
alloc(ptr);
printf("ptr = %p\n",ptr);
return 0;
}
/Per W
On Sat, 28 Feb 2004, David McKen wrote:
> you apparently did not read the end of my message,
>
> I know how to create a pointer to a pointer (**) I haven't heard
> about a
> refrence to a pointer (&* ?), what is the syntax for such a variable?
>
> ----- Original Message -----
> From: "Per Westermark" <pw...@ia...>
> To: "David McKen" <ci...@ya...>
> Cc: "Mailing List, Dev-Cpp" <dev...@li...>
> Sent: Saturday, February 28, 2004 5:27 AM
> Subject: Re: [Dev-C++] Crash with macro to template conversion
>
>
> > But you have not fixed the declaration of the ptr parameter yet.
> Any
> > allocations you make will behave ok inside the create() function,
> but the
> > caller will never get the value of the allocated pointer! You
> REALLY MUST
> > change del parameter declaration to either be a pointer to a
> pointer, or a
> > reference to a pointer!
> >
> > /Per W
> >
> > On Fri, 27 Feb 2004, David McKen wrote:
> >
> > > Sorry about that the correct definition is:
> > > template<class T>
> > > void create(T * ptr, int number, char * f_name = __FILE__, int
> l_num
> > > =
> > > __LINE__)
> > > {
> > > ptr = new T[number];
> > > if ( !ptr )
> > > {
> > > perror("malloc failure");
> > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name, l_num );
> > > abort();
> > > }
> > > }
> > >
> > > All the exception stuff was just trying to figure out if an error
> is
> > > even
> > > occuring.
> > >
> > > I am trying to keep to convention. The macro is not my code but
> code
> > > I am
> > > trying to replace. I am very tempted to change it but I also have
> > > RECREATE
> > > (wraps realloc()) and DESTROY (wraps free() ) which also need to
> be
> > > replaced. I could use macros to alter the function call but I am
> > > trying to
> > > remove all the macros I can (got some linked list macros to
> replace
> > > as well)
> > >
> > > So...How does one create a refrence to a pointer?
> > >
> > > ----- Original Message -----
> > > From: "Per Westermark" <pw...@ia...>
> > > To: "David McKen" <ci...@ya...>
> > > Cc: "Mailing List, Dev-Cpp" <dev...@li...>
> > > Sent: Friday, February 27, 2004 7:08 AM
> > > Subject: Re: [Dev-C++] Crash with macro to template conversion
> > >
> > >
> > > > First of all - your create template function is declared to
> return
> > > void,
> > > > so why do you end it with return ptr?
> > > >
> > > > Second, you send in a T* ptr parameter. Note that since C++
> uses
> > > > call-by-value, this will behave like a lokal variable, i.e any
> > > assign to
> > > > ptr will not reflect back to the caller. You should change the
> > > first
> > > > parameter of create to be a reference to a pointer. That way,
> the
> > > assign
> > > > to ptr will reflect back to the variable obj of the caller.
> > > >
> > > > /Per W
> > > >
> > > > On Fri, 27 Feb 2004, David McKen wrote:
> > > >
> > > > > Ok here is my problem.
> > > > >
> > > > > I want to replace:
> > > > > #define CREATE(result, type, number) \
> > > > > do \
> > > > > { \
> > > > > if (!((result) = (type *) calloc ((number),
> sizeof(type)))) \
> > > > > { \
> > > > > perror("malloc failure"); \
> > > > > fprintf(stderr, "Malloc failure @ %s:%d\n", __FILE__,
> > > __LINE__ );
> > > > > \
> > > > > abort(); \
> > > > > } \
> > > > > } while(0)
> > > > >
> > > > > With it's C++ equivalent.
> > > > >
> > > > > So far I have:
> > > > > #define CREATE(result, type, num)
> create<type>((result),(num))
> > > > > template<class T>
> > > > > void create(T * ptr, int number, char * f_name = __FILE__,
> int
> > > l_num
> > > > > =
> > > > > __LINE__)
> > > > > {
> > > > > try {
> > > > > ptr = new T[number];
> > > > > }
> > > > > catch(bad_alloc& b)
> > > > > {
> > > > > perror("malloc failure");
> > > > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name,
> l_num );
> > > > > abort();
> > > > > }
> > > > > if ( !ptr )
> > > > > {
> > > > > perror("malloc failure");
> > > > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name,
> l_num );
> > > > > abort();
> > > > > }
> > > > > return ptr;
> > > > > }
> > > > >
> > > > > But the program crashes after the function call when any
> attempt
> > > to
> > > > > acces
> > > > > the data occours:
> > > > > e.g.
> > > > > OBJ_DATA * obj;
> > > > > CREATE( obj , OBJ_DATA, 1 );
> > > > >
> > > > > obj->some_field = 5; //Crashes here and obj = 0x0 from gdb.
> > > > >
> > > > > Thanks in Advance
> > > > > David McKen
> > > > >
> > > > >
> > > > > __________________________________
> > > > > Do you Yahoo!?
> > > > > Get better spam protection with Yahoo! Mail.
> > > > > http://antispam.yahoo.com/tools
> > > > >
> > > > >
> > > > > -------------------------------------------------------
> > > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > > Build and deploy apps & Web services for Linux with
> > > > > a free DVD software kit from IBM. Click Now!
> > > > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > > > _______________________________________________
> > > > > Dev-cpp-users mailing list
> > > > > Dev...@li...
> > > > > TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > > >
> > > >
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > Build and deploy apps & Web services for Linux with
> > > > a free DVD software kit from IBM. Click Now!
> > > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > > _______________________________________________
> > > > Dev-cpp-users mailing list
> > > > Dev...@li...
> > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > Get better spam protection with Yahoo! Mail.
> > > http://antispam.yahoo.com/tools
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> __________________________________
> Do you Yahoo!?
> Get better spam protection with Yahoo! Mail.
> http://antispam.yahoo.com/tools
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Emiliano <sky...@fa...> - 2004-02-28 23:46:09
|
Does windows support static libraries? I include jpeg.lib (or any other .lib/.a file) into my project, but, when executing, windows complains about "jpeglib6b.dll" missing. This is not a big problem with other libraries coming with a .dll file, but jpeglib misses that one, and I don't want to compile it from scratch... at least would avoid that :) regards, Emiliano |
|
From: Daniel K. O. <dan...@ya...> - 2004-02-28 23:55:40
|
Emiliano wrote: >Does windows support static libraries? > >I include jpeg.lib (or any other .lib/.a file) into my project, but, when >executing, windows complains about "jpeglib6b.dll" missing. > >This is not a big problem with other libraries coming with a .dll file, but >jpeglib misses that one, and I don't want to compile it from scratch... at >least would avoid that :) > > Some libs - like the libjpeg - have different dll versions for the same thing. The lib you have is for another dll compilation. I had a problem recently with libFLAC; the lib was exporting some MD5 symbols, that were conflicting with the program. So I linked directly to the libFLAC.dll - yes, MinGW can also link directly to the .dll, just add it to the linker options. Or, if it doesn't work, go to gnuwin32 page and download the libjpeg from them. Daniel K. O. |
|
From: Emiliano <sky...@fa...> - 2004-02-29 00:12:26
|
Many thanks: I had to link with "-ljpeg", now it seems to work. BUT, do I _always_ need to have external dlls coming with my app? Or is there a way to include libraries into the executable? This is the way it works on other systems... Emiliano ----- Original Message ----- From: "Daniel K. O." <dan...@ya...> To: "Emiliano" <sky...@fa...> Cc: <dev...@li...> Sent: Sunday, February 29, 2004 12:44 AM Subject: Re: [Dev-C++] Another one with static libraries. > Emiliano wrote: > > >Does windows support static libraries? > > > >I include jpeg.lib (or any other .lib/.a file) into my project, but, when > >executing, windows complains about "jpeglib6b.dll" missing. > > > >This is not a big problem with other libraries coming with a .dll file, but > >jpeglib misses that one, and I don't want to compile it from scratch... at > >least would avoid that :) > > > > > > Some libs - like the libjpeg - have different dll versions for the same > thing. The lib you have is for another dll compilation. > I had a problem recently with libFLAC; the lib was exporting some MD5 > symbols, that were conflicting with the program. So I linked directly to > the libFLAC.dll - yes, MinGW can also link directly to the .dll, just > add it to the linker options. > > Or, if it doesn't work, go to gnuwin32 page and download the libjpeg > from them. > > > > Daniel K. O. > > > > ------------------------------------------------------- > SF.Net is sponsored by: Speed Start Your Linux Apps Now. > Build and deploy apps & Web services for Linux with > a free DVD software kit from IBM. Click Now! > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
|
From: <or...@vp...> - 2004-02-29 01:00:54
|
Emiliano wrote: > Many thanks: I had to link with "-ljpeg", now it seems to work. >=20 > BUT, do I _always_ need to have external dlls coming with my app? Or is > there a way to include libraries into the executable? Sure, just compile the static version of the library, and recompile the=20 exe. The symbols will be linked in. > This is the way it works on other systems... Well, on Linux, mostly dynamic libraries are used. (.so files) -- Greetings, Bal=E1zs |
|
From: Emiliano <sky...@fa...> - 2004-02-29 08:19:54
|
Sorry but Outlook decided not to quote this morning... I'll try manually. >Sure, just compile the static version of the library, and recompile >the >exe. The symbols will be linked in. Please explain me what to do exactly. If I have understood, I need to put into my project the source files of the library too? I thought it was enough to put into the linker parameters the ".a/.lib" file... >> This is the way it works on other systems... >Well, on Linux, mostly dynamic libraries are used. (.so files) I know that, I LIKE shared stuff (libs, resources, memory and so on :)), and a lot. But for convenience reasons, now it would be MUCH better for me to have just a single executable and NO scattered files. I need to put into it just a couple of libs. Thanks for your attention, Emiliano |
|
From: <or...@vp...> - 2004-02-29 15:47:33
|
Emiliano wrote: >>Sure, just compile the static version of the library, and recompile >th= e >>exe. The symbols will be linked in. >=20 > Please explain me what to do exactly. If I have understood, I need to p= ut > into my project the source files of the library too? I thought it was e= nough > to put into the linker parameters the ".a/.lib" file... No, you don't need to put the sources into the project. Actually, that=20 should never be done. You need to get the sources of the library, that you wish to use (in=20 this case jpeglib?). Then compile the static version of the library. How=20 to do that? Well, it depends heavily on the library that you're using.=20 Look around in the docs of the library to see how to compile the static=20 version of it. It will get you a libxxx.a file, where possibly xxx is=20 the name of the library. Then place it to a place, where GCC (Dev-C++)=20 can find it (maybe <DEVCPP>\lib), then add -lxxx to your project librarie= s. The symbols will be "hard-linked" into the exe from the lib. -- Greetings, Bal=E1zs |
|
From: David M. <ci...@ya...> - 2004-02-29 00:57:24
|
Thanks,
Just a question for future refrence but can the "pointer to" chain go
infinitely?
i.e.
Does char *** x make a pointer-to-a-pointer-to-a-pointer-to-a-char ?
Also refrences cannot be chained, right? That would be the logical
AND
operator anyway.
----- Original Message -----
From: "Per Westermark" <pw...@ia...>
To: "David McKen" <ci...@ya...>
Cc: "Mailing List, Dev-Cpp" <dev...@li...>
Sent: Saturday, February 28, 2004 3:20 PM
Subject: Re: [Dev-C++] Crash with macro to template conversion
> Oops. Too quick answer :-)
> With the following construct, the caller will get back the newly
allocated
> pointer:
>
> void alloc(char*& ptr) {
> ptr = new char[10];
> }
>
> int main() {
> char *ptr = NULL;
> printf("ptr = %p\n",ptr);
> alloc(ptr);
> printf("ptr = %p\n",ptr);
> return 0;
> }
>
> /Per W
>
> On Sat, 28 Feb 2004, David McKen wrote:
>
> > you apparently did not read the end of my message,
> >
> > I know how to create a pointer to a pointer (**) I haven't heard
> > about a
> > refrence to a pointer (&* ?), what is the syntax for such a
variable?
> >
> > ----- Original Message -----
> > From: "Per Westermark" <pw...@ia...>
> > To: "David McKen" <ci...@ya...>
> > Cc: "Mailing List, Dev-Cpp" <dev...@li...>
> > Sent: Saturday, February 28, 2004 5:27 AM
> > Subject: Re: [Dev-C++] Crash with macro to template conversion
> >
> >
> > > But you have not fixed the declaration of the ptr parameter
yet.
> > Any
> > > allocations you make will behave ok inside the create()
function,
> > but the
> > > caller will never get the value of the allocated pointer! You
> > REALLY MUST
> > > change del parameter declaration to either be a pointer to a
> > pointer, or a
> > > reference to a pointer!
> > >
> > > /Per W
> > >
> > > On Fri, 27 Feb 2004, David McKen wrote:
> > >
> > > > Sorry about that the correct definition is:
> > > > template<class T>
> > > > void create(T * ptr, int number, char * f_name = __FILE__,
int
> > l_num
> > > > =
> > > > __LINE__)
> > > > {
> > > > ptr = new T[number];
> > > > if ( !ptr )
> > > > {
> > > > perror("malloc failure");
> > > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name,
l_num );
> > > > abort();
> > > > }
> > > > }
> > > >
> > > > All the exception stuff was just trying to figure out if an
error
> > is
> > > > even
> > > > occuring.
> > > >
> > > > I am trying to keep to convention. The macro is not my code
but
> > code
> > > > I am
> > > > trying to replace. I am very tempted to change it but I also
have
> > > > RECREATE
> > > > (wraps realloc()) and DESTROY (wraps free() ) which also need
to
> > be
> > > > replaced. I could use macros to alter the function call but I
am
> > > > trying to
> > > > remove all the macros I can (got some linked list macros to
> > replace
> > > > as well)
> > > >
> > > > So...How does one create a refrence to a pointer?
> > > >
> > > > ----- Original Message -----
> > > > From: "Per Westermark" <pw...@ia...>
> > > > To: "David McKen" <ci...@ya...>
> > > > Cc: "Mailing List, Dev-Cpp"
<dev...@li...>
> > > > Sent: Friday, February 27, 2004 7:08 AM
> > > > Subject: Re: [Dev-C++] Crash with macro to template
conversion
> > > >
> > > >
> > > > > First of all - your create template function is declared to
> > return
> > > > void,
> > > > > so why do you end it with return ptr?
> > > > >
> > > > > Second, you send in a T* ptr parameter. Note that since C++
> > uses
> > > > > call-by-value, this will behave like a lokal variable, i.e
any
> > > > assign to
> > > > > ptr will not reflect back to the caller. You should change
the
> > > > first
> > > > > parameter of create to be a reference to a pointer. That
way,
> > the
> > > > assign
> > > > > to ptr will reflect back to the variable obj of the caller.
> > > > >
> > > > > /Per W
> > > > >
> > > > > On Fri, 27 Feb 2004, David McKen wrote:
> > > > >
> > > > > > Ok here is my problem.
> > > > > >
> > > > > > I want to replace:
> > > > > > #define CREATE(result, type, number) \
> > > > > > do \
> > > > > > { \
> > > > > > if (!((result) = (type *) calloc ((number),
> > sizeof(type)))) \
> > > > > > { \
> > > > > > perror("malloc failure"); \
> > > > > > fprintf(stderr, "Malloc failure @ %s:%d\n", __FILE__,
> > > > __LINE__ );
> > > > > > \
> > > > > > abort(); \
> > > > > > } \
> > > > > > } while(0)
> > > > > >
> > > > > > With it's C++ equivalent.
> > > > > >
> > > > > > So far I have:
> > > > > > #define CREATE(result, type, num)
> > create<type>((result),(num))
> > > > > > template<class T>
> > > > > > void create(T * ptr, int number, char * f_name =
__FILE__,
> > int
> > > > l_num
> > > > > > =
> > > > > > __LINE__)
> > > > > > {
> > > > > > try {
> > > > > > ptr = new T[number];
> > > > > > }
> > > > > > catch(bad_alloc& b)
> > > > > > {
> > > > > > perror("malloc failure");
> > > > > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name,
> > l_num );
> > > > > > abort();
> > > > > > }
> > > > > > if ( !ptr )
> > > > > > {
> > > > > > perror("malloc failure");
> > > > > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name,
> > l_num );
> > > > > > abort();
> > > > > > }
> > > > > > return ptr;
> > > > > > }
> > > > > >
> > > > > > But the program crashes after the function call when any
> > attempt
> > > > to
> > > > > > acces
> > > > > > the data occours:
> > > > > > e.g.
> > > > > > OBJ_DATA * obj;
> > > > > > CREATE( obj , OBJ_DATA, 1 );
> > > > > >
> > > > > > obj->some_field = 5; //Crashes here and obj = 0x0 from
gdb.
> > > > > >
> > > > > > Thanks in Advance
> > > > > > David McKen
> > > > > >
> > > > > >
> > > > > > __________________________________
> > > > > > Do you Yahoo!?
> > > > > > Get better spam protection with Yahoo! Mail.
> > > > > > http://antispam.yahoo.com/tools
> > > > > >
> > > > > >
> > > > > > -------------------------------------------------------
> > > > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > > > Build and deploy apps & Web services for Linux with
> > > > > > a free DVD software kit from IBM. Click Now!
> > > > > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > > > > _______________________________________________
> > > > > > Dev-cpp-users mailing list
> > > > > > Dev...@li...
> > > > > > TO UNSUBSCRIBE:
> > http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > >
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > -------------------------------------------------------
> > > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > > Build and deploy apps & Web services for Linux with
> > > > > a free DVD software kit from IBM. Click Now!
> > > > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > > > _______________________________________________
> > > > > Dev-cpp-users mailing list
> > > > > Dev...@li...
> > > > > TO UNSUBSCRIBE:
http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > >
> > > >
> > > > __________________________________
> > > > Do you Yahoo!?
> > > > Get better spam protection with Yahoo! Mail.
> > > > http://antispam.yahoo.com/tools
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > Build and deploy apps & Web services for Linux with
> > > > a free DVD software kit from IBM. Click Now!
> > > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > > _______________________________________________
> > > > Dev-cpp-users mailing list
> > > > Dev...@li...
> > > > TO UNSUBSCRIBE:
http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > >
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > Get better spam protection with Yahoo! Mail.
> > http://antispam.yahoo.com/tools
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
__________________________________
Do you Yahoo!?
Get better spam protection with Yahoo! Mail.
http://antispam.yahoo.com/tools
|
|
From: Per W. <pw...@ia...> - 2004-02-29 01:19:57
|
Yes, you can continue to cascade the pointers to pointers to... but with a
correctly written program you never need to since the goal of the program
is to either move the pointer or what the pointer points to.
/Per W
On Sat, 28 Feb 2004, David McKen wrote:
> Thanks,
>
> Just a question for future refrence but can the "pointer to" chain go
> infinitely?
> i.e.
> Does char *** x make a pointer-to-a-pointer-to-a-pointer-to-a-char ?
>
> Also refrences cannot be chained, right? That would be the logical
> AND
> operator anyway.
>
> ----- Original Message -----
> From: "Per Westermark" <pw...@ia...>
> To: "David McKen" <ci...@ya...>
> Cc: "Mailing List, Dev-Cpp" <dev...@li...>
> Sent: Saturday, February 28, 2004 3:20 PM
> Subject: Re: [Dev-C++] Crash with macro to template conversion
>
>
> > Oops. Too quick answer :-)
> > With the following construct, the caller will get back the newly
> allocated
> > pointer:
> >
> > void alloc(char*& ptr) {
> > ptr = new char[10];
> > }
> >
> > int main() {
> > char *ptr = NULL;
> > printf("ptr = %p\n",ptr);
> > alloc(ptr);
> > printf("ptr = %p\n",ptr);
> > return 0;
> > }
> >
> > /Per W
> >
> > On Sat, 28 Feb 2004, David McKen wrote:
> >
> > > you apparently did not read the end of my message,
> > >
> > > I know how to create a pointer to a pointer (**) I haven't heard
> > > about a
> > > refrence to a pointer (&* ?), what is the syntax for such a
> variable?
> > >
> > > ----- Original Message -----
> > > From: "Per Westermark" <pw...@ia...>
> > > To: "David McKen" <ci...@ya...>
> > > Cc: "Mailing List, Dev-Cpp" <dev...@li...>
> > > Sent: Saturday, February 28, 2004 5:27 AM
> > > Subject: Re: [Dev-C++] Crash with macro to template conversion
> > >
> > >
> > > > But you have not fixed the declaration of the ptr parameter
> yet.
> > > Any
> > > > allocations you make will behave ok inside the create()
> function,
> > > but the
> > > > caller will never get the value of the allocated pointer! You
> > > REALLY MUST
> > > > change del parameter declaration to either be a pointer to a
> > > pointer, or a
> > > > reference to a pointer!
> > > >
> > > > /Per W
> > > >
> > > > On Fri, 27 Feb 2004, David McKen wrote:
> > > >
> > > > > Sorry about that the correct definition is:
> > > > > template<class T>
> > > > > void create(T * ptr, int number, char * f_name = __FILE__,
> int
> > > l_num
> > > > > =
> > > > > __LINE__)
> > > > > {
> > > > > ptr = new T[number];
> > > > > if ( !ptr )
> > > > > {
> > > > > perror("malloc failure");
> > > > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name,
> l_num );
> > > > > abort();
> > > > > }
> > > > > }
> > > > >
> > > > > All the exception stuff was just trying to figure out if an
> error
> > > is
> > > > > even
> > > > > occuring.
> > > > >
> > > > > I am trying to keep to convention. The macro is not my code
> but
> > > code
> > > > > I am
> > > > > trying to replace. I am very tempted to change it but I also
> have
> > > > > RECREATE
> > > > > (wraps realloc()) and DESTROY (wraps free() ) which also need
> to
> > > be
> > > > > replaced. I could use macros to alter the function call but I
> am
> > > > > trying to
> > > > > remove all the macros I can (got some linked list macros to
> > > replace
> > > > > as well)
> > > > >
> > > > > So...How does one create a refrence to a pointer?
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "Per Westermark" <pw...@ia...>
> > > > > To: "David McKen" <ci...@ya...>
> > > > > Cc: "Mailing List, Dev-Cpp"
> <dev...@li...>
> > > > > Sent: Friday, February 27, 2004 7:08 AM
> > > > > Subject: Re: [Dev-C++] Crash with macro to template
> conversion
> > > > >
> > > > >
> > > > > > First of all - your create template function is declared to
> > > return
> > > > > void,
> > > > > > so why do you end it with return ptr?
> > > > > >
> > > > > > Second, you send in a T* ptr parameter. Note that since C++
> > > uses
> > > > > > call-by-value, this will behave like a lokal variable, i.e
> any
> > > > > assign to
> > > > > > ptr will not reflect back to the caller. You should change
> the
> > > > > first
> > > > > > parameter of create to be a reference to a pointer. That
> way,
> > > the
> > > > > assign
> > > > > > to ptr will reflect back to the variable obj of the caller.
> > > > > >
> > > > > > /Per W
> > > > > >
> > > > > > On Fri, 27 Feb 2004, David McKen wrote:
> > > > > >
> > > > > > > Ok here is my problem.
> > > > > > >
> > > > > > > I want to replace:
> > > > > > > #define CREATE(result, type, number) \
> > > > > > > do \
> > > > > > > { \
> > > > > > > if (!((result) = (type *) calloc ((number),
> > > sizeof(type)))) \
> > > > > > > { \
> > > > > > > perror("malloc failure"); \
> > > > > > > fprintf(stderr, "Malloc failure @ %s:%d\n", __FILE__,
> > > > > __LINE__ );
> > > > > > > \
> > > > > > > abort(); \
> > > > > > > } \
> > > > > > > } while(0)
> > > > > > >
> > > > > > > With it's C++ equivalent.
> > > > > > >
> > > > > > > So far I have:
> > > > > > > #define CREATE(result, type, num)
> > > create<type>((result),(num))
> > > > > > > template<class T>
> > > > > > > void create(T * ptr, int number, char * f_name =
> __FILE__,
> > > int
> > > > > l_num
> > > > > > > =
> > > > > > > __LINE__)
> > > > > > > {
> > > > > > > try {
> > > > > > > ptr = new T[number];
> > > > > > > }
> > > > > > > catch(bad_alloc& b)
> > > > > > > {
> > > > > > > perror("malloc failure");
> > > > > > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name,
> > > l_num );
> > > > > > > abort();
> > > > > > > }
> > > > > > > if ( !ptr )
> > > > > > > {
> > > > > > > perror("malloc failure");
> > > > > > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name,
> > > l_num );
> > > > > > > abort();
> > > > > > > }
> > > > > > > return ptr;
> > > > > > > }
> > > > > > >
> > > > > > > But the program crashes after the function call when any
> > > attempt
> > > > > to
> > > > > > > acces
> > > > > > > the data occours:
> > > > > > > e.g.
> > > > > > > OBJ_DATA * obj;
> > > > > > > CREATE( obj , OBJ_DATA, 1 );
> > > > > > >
> > > > > > > obj->some_field = 5; //Crashes here and obj = 0x0 from
> gdb.
> > > > > > >
> > > > > > > Thanks in Advance
> > > > > > > David McKen
> > > > > > >
> > > > > > >
> > > > > > > __________________________________
> > > > > > > Do you Yahoo!?
> > > > > > > Get better spam protection with Yahoo! Mail.
> > > > > > > http://antispam.yahoo.com/tools
> > > > > > >
> > > > > > >
> > > > > > > -------------------------------------------------------
> > > > > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > > > > Build and deploy apps & Web services for Linux with
> > > > > > > a free DVD software kit from IBM. Click Now!
> > > > > > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > > > > > _______________________________________________
> > > > > > > Dev-cpp-users mailing list
> > > > > > > Dev...@li...
> > > > > > > TO UNSUBSCRIBE:
> > > http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > > >
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > -------------------------------------------------------
> > > > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > > > Build and deploy apps & Web services for Linux with
> > > > > > a free DVD software kit from IBM. Click Now!
> > > > > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > > > > _______________________________________________
> > > > > > Dev-cpp-users mailing list
> > > > > > Dev...@li...
> > > > > > TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > > >
> > > > >
> > > > > __________________________________
> > > > > Do you Yahoo!?
> > > > > Get better spam protection with Yahoo! Mail.
> > > > > http://antispam.yahoo.com/tools
> > > > >
> > > > >
> > > > > -------------------------------------------------------
> > > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > > Build and deploy apps & Web services for Linux with
> > > > > a free DVD software kit from IBM. Click Now!
> > > > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > > > _______________________________________________
> > > > > Dev-cpp-users mailing list
> > > > > Dev...@li...
> > > > > TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > > >
> > > >
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > > Build and deploy apps & Web services for Linux with
> > > > a free DVD software kit from IBM. Click Now!
> > > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > > _______________________________________________
> > > > Dev-cpp-users mailing list
> > > > Dev...@li...
> > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > Get better spam protection with Yahoo! Mail.
> > > http://antispam.yahoo.com/tools
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> __________________________________
> Do you Yahoo!?
> Get better spam protection with Yahoo! Mail.
> http://antispam.yahoo.com/tools
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Per W. <pw...@ia...> - 2004-02-28 13:38:26
|
But you have not fixed the declaration of the ptr parameter yet. Any
allocations you make will behave ok inside the create() function, but the
caller will never get the value of the allocated pointer! You REALLY MUST
change del parameter declaration to either be a pointer to a pointer, or a
reference to a pointer!
/Per W
On Fri, 27 Feb 2004, David McKen wrote:
> Sorry about that the correct definition is:
> template<class T>
> void create(T * ptr, int number, char * f_name = __FILE__, int l_num
> =
> __LINE__)
> {
> ptr = new T[number];
> if ( !ptr )
> {
> perror("malloc failure");
> fprintf( stderr, "Malloc failure @ %s:%d\n", f_name, l_num );
> abort();
> }
> }
>
> All the exception stuff was just trying to figure out if an error is
> even
> occuring.
>
> I am trying to keep to convention. The macro is not my code but code
> I am
> trying to replace. I am very tempted to change it but I also have
> RECREATE
> (wraps realloc()) and DESTROY (wraps free() ) which also need to be
> replaced. I could use macros to alter the function call but I am
> trying to
> remove all the macros I can (got some linked list macros to replace
> as well)
>
> So...How does one create a refrence to a pointer?
>
> ----- Original Message -----
> From: "Per Westermark" <pw...@ia...>
> To: "David McKen" <ci...@ya...>
> Cc: "Mailing List, Dev-Cpp" <dev...@li...>
> Sent: Friday, February 27, 2004 7:08 AM
> Subject: Re: [Dev-C++] Crash with macro to template conversion
>
>
> > First of all - your create template function is declared to return
> void,
> > so why do you end it with return ptr?
> >
> > Second, you send in a T* ptr parameter. Note that since C++ uses
> > call-by-value, this will behave like a lokal variable, i.e any
> assign to
> > ptr will not reflect back to the caller. You should change the
> first
> > parameter of create to be a reference to a pointer. That way, the
> assign
> > to ptr will reflect back to the variable obj of the caller.
> >
> > /Per W
> >
> > On Fri, 27 Feb 2004, David McKen wrote:
> >
> > > Ok here is my problem.
> > >
> > > I want to replace:
> > > #define CREATE(result, type, number) \
> > > do \
> > > { \
> > > if (!((result) = (type *) calloc ((number), sizeof(type)))) \
> > > { \
> > > perror("malloc failure"); \
> > > fprintf(stderr, "Malloc failure @ %s:%d\n", __FILE__,
> __LINE__ );
> > > \
> > > abort(); \
> > > } \
> > > } while(0)
> > >
> > > With it's C++ equivalent.
> > >
> > > So far I have:
> > > #define CREATE(result, type, num) create<type>((result),(num))
> > > template<class T>
> > > void create(T * ptr, int number, char * f_name = __FILE__, int
> l_num
> > > =
> > > __LINE__)
> > > {
> > > try {
> > > ptr = new T[number];
> > > }
> > > catch(bad_alloc& b)
> > > {
> > > perror("malloc failure");
> > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name, l_num );
> > > abort();
> > > }
> > > if ( !ptr )
> > > {
> > > perror("malloc failure");
> > > fprintf( stderr, "Malloc failure @ %s:%d\n", f_name, l_num );
> > > abort();
> > > }
> > > return ptr;
> > > }
> > >
> > > But the program crashes after the function call when any attempt
> to
> > > acces
> > > the data occours:
> > > e.g.
> > > OBJ_DATA * obj;
> > > CREATE( obj , OBJ_DATA, 1 );
> > >
> > > obj->some_field = 5; //Crashes here and obj = 0x0 from gdb.
> > >
> > > Thanks in Advance
> > > David McKen
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > Get better spam protection with Yahoo! Mail.
> > > http://antispam.yahoo.com/tools
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> __________________________________
> Do you Yahoo!?
> Get better spam protection with Yahoo! Mail.
> http://antispam.yahoo.com/tools
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|