Thread: [Dev-C++] what is a resource? how do I create my own headers?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Alan T. <ala...@3n...> - 2001-01-04 01:48:27
|
Two questions:
(a) What is a "resource" file? Is it relevant for a [DOS] console program?
Where is it documented what to do with a resource file?
I created a new project (console application) and added three
existing files (two cpp{one with a main function, another with other
functions} and one header file. Asked it to Compile the project, but it
gave me an error with the resources ("no resources"). Tried again with a
new, empty project. Added files but got same error when I attempted to
compile.
(b) How do I save/use a header file?
I have some functions. Wrote and tested them. Took the function
prototypes and #includes, and made them the header file. Included it
(#include "html.h") in my file with the main function. Took the rest ---
the function definitions --- and made them the .cpp file. Is this the way
you use a header file?
Where is this documented or described?
Thanks, Alan
|
|
From: Ramana K. <ra...@my...> - 2001-01-04 02:14:13
|
A resource file is not needed for a dos project. You shouldn't be getting any errors if you don't touch the resource file, but, if you do, go to Project Options and remove the text in the resource file field, or, open the resource file and edit it (delete its contents). As far as I know, this is how you use header files, this is how I use them but sometimes I don't see the point if you know the function will not be used later. If this is the case, keep the whole function in one file (a .h file if it happens to be) and then you can include this as a file full of functions in a project (used in a .cpp file like main.cpp). Ramana Kumar ICQ# 93667117 To get paid for surfing the 'net please visit https://www.alladvantage.com/joinsecure.asp?refid=jpn471 -----Original Message----- From: dev...@li... [mailto:dev...@li...]On Behalf Of Alan Thomas Sent: Thursday, January 04, 2001 12:46 PM To: dev...@li... Subject: [Dev-C++] what is a resource? how do I create my own headers? Importance: High Two questions: (a) What is a "resource" file? Is it relevant for a [DOS] console program? Where is it documented what to do with a resource file? I created a new project (console application) and added three existing files (two cpp{one with a main function, another with other functions} and one header file. Asked it to Compile the project, but it gave me an error with the resources ("no resources"). Tried again with a new, empty project. Added files but got same error when I attempted to compile. (b) How do I save/use a header file? I have some functions. Wrote and tested them. Took the function prototypes and #includes, and made them the header file. Included it (#include "html.h") in my file with the main function. Took the rest --- the function definitions --- and made them the .cpp file. Is this the way you use a header file? Where is this documented or described? Thanks, Alan _______________________________________________ Dev-cpp-users mailing list Dev...@li... http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users |
|
From: Luc M. <lu...@ho...> - 2001-01-04 02:58:14
|
----- Original Message ----- From: "Ramana Kumar" <ra...@my...> To: <dev...@li...> Sent: Wednesday, January 03, 2001 9:16 PM Subject: RE: [Dev-C++] what is a resource? how do I create my own headers? > > As far as I know, this is how you use header files, this is how I use them > but sometimes I don't see the point if you know the function will not be > used later. If this is the case, keep the whole function in one file (a .h > file if it happens to be) and then you can include this as a file full of > functions in a project (used in a .cpp file like main.cpp). > > Ramana Kumar > ICQ# 93667117 > To get paid for surfing the 'net please visit > https://www.alladvantage.com/joinsecure.asp?refid=jpn471 > It is not a very good idea to put definitions in a header file. Next thing you know, you include the file from another translation unit and you get multiple definitions problems. I'd advise that if the function is gonna be used only in one translation unit to put the function in that very same translation unit (declaration AND definition). Just my $0.02 Luc Morin |
|
From: Ioannis V. <no...@ya...> - 2001-01-04 15:05:52
|
He can use the following notation so as to bbe protected from multiple includes. #ifndef PINKY&THE_BRAIN #define PINKY&THE_BRAIN // implementation stuff #endif Ioannis > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...]On Behalf Of Luc Morin > Sent: Thursday, January 04, 2001 4:59 AM > To: dev...@li... > Subject: Re: [Dev-C++] what is a resource? how do I create my own headers? > > > > ----- Original Message ----- > From: "Ramana Kumar" <ra...@my...> > To: <dev...@li...> > Sent: Wednesday, January 03, 2001 9:16 PM > Subject: RE: [Dev-C++] what is a resource? how do I create my own headers? > > > > > > As far as I know, this is how you use header files, this is how > I use them > > but sometimes I don't see the point if you know the function will not be > > used later. If this is the case, keep the whole function in one > file (a .h > > file if it happens to be) and then you can include this as a > file full of > > functions in a project (used in a .cpp file like main.cpp). > > > > Ramana Kumar > > ICQ# 93667117 > > To get paid for surfing the 'net please visit > > https://www.alladvantage.com/joinsecure.asp?refid=jpn471 > > > > It is not a very good idea to put definitions in a header file. Next thing > you know, > you include the file from another translation unit and you get multiple > definitions > problems. > > I'd advise that if the function is gonna be used only in one translation > unit to put > the function in that very same translation unit (declaration AND > definition). > > Just my $0.02 > > Luc Morin > > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users > |
|
From: Luc M. <lu...@ho...> - 2001-01-04 23:28:31
|
----- Original Message ----- From: "Ioannis Vranos" <no...@ya...> To: <dev...@li...> Sent: Thursday, January 04, 2001 10:07 AM Subject: RE: [Dev-C++] what is a resource? how do I create my own headers? > He can use the following notation so as to bbe protected from multiple > includes. > > #ifndef PINKY&THE_BRAIN > > #define PINKY&THE_BRAIN > // implementation stuff > #endif > > > Ioannis > While I do agree that this will protect agaisnt multiple _inclusion_, it will NOT protect agaisnt multiple _definition_ of a function located in a header file. The #ifdef/#endif only works for the current compile. So, if you include a header file that contains a definition in more than one translation unit (.cpp file), you will get multiple definitions of the function, which is gonna be flagged as an error by the linker. Regards, Luc Morin |
|
From: Ioannis V. <no...@ya...> - 2001-01-04 23:50:25
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...]On Behalf Of Luc Morin > Sent: Friday, January 05, 2001 1:29 AM > To: dev...@li... > Subject: Re: [Dev-C++] what is a resource? how do I create my own headers? > > While I do agree that this will protect agaisnt multiple _inclusion_, it > will > NOT protect agaisnt multiple _definition_ of a function located > in a header > file. > > The #ifdef/#endif only works for the current compile. So, if you include > a header file that contains a definition in more than one translation unit > (.cpp file), you will get multiple definitions of the function, which is > gonna > be flagged as an error by the linker. I agree with you, but why create many definitions in many cpp files? Except of that, you can use #ifndef at definitions too (it is called "conditional compilation"). Anyway, if i remember well we were talking about definitions included in the header file, not external source code files (where as i said we can use conditional compilation too). Friendly, Ioannis * Ioannis Vranos * Programming pages: http://members.nbci.com/noicys * Alternative URL: http://run.to/noicys |
|
From: Luc M. <lu...@ho...> - 2001-01-05 02:39:20
|
----- Original Message ----- From: "Ioannis Vranos" <no...@ya...> To: <dev...@li...> Sent: Thursday, January 04, 2001 6:52 PM Subject: RE: [Dev-C++] what is a resource? how do I create my own headers? > > The #ifdef/#endif only works for the current compile. So, if you include > > a header file that contains a definition in more than one translation unit > > (.cpp file), you will get multiple definitions of the function, which is > > gonna > > be flagged as an error by the linker. > > I agree with you, but why create many definitions in many cpp files? Except > of that, you can use #ifndef at definitions too (it is called "conditional > compilation"). > Anyway, if i remember well we were talking about definitions included in > the header file, not external source code files (where as i said we can use > conditional compilation too). I don't see where I might have hinted at having "many definition in many .cpp files". In C/C++ (I don't know for other languages), you can't have more than one definition for a symbol, be it a variable, a function or a class. This is called, IIRC, the "One Definition Rule". If you start putting definitions in header files, as projects grow bigger, those header files risk being included in more than one .cpp file, leading to multiple definitions of the functions in the header files. Now, I've seen tricks posted here to work around this, but why use tricks when all you have to do is _declare_ your functions (or classes) in a header file, and _define_ said functions (or classes) in only one .cpp file. Then, wherever you need that function, all you need to do is #include your header file. Let the linker do its job :-) Regards, Luc Morin |
|
From: <ste...@ge...> - 2001-01-05 15:09:55
|
Ah, what is implementation stuff?? Can someone give an example? :-) Thanks. ----- Original Message -----=20 From: "Ioannis Vranos" <no...@ya...> To: <dev...@li...> Sent: Thursday, January 04, 2001 7:07 AM Subject: RE: [Dev-C++] what is a resource? how do I create my own = headers? > He can use the following notation so as to bbe protected from multiple > includes. >=20 > #ifndef PINKY&THE_BRAIN >=20 > #define PINKY&THE_BRAIN > // implementation stuff > #endif >=20 >=20 > Ioannis >=20 > > -----Original Message----- > > From: dev...@li... > > [mailto:dev...@li...]On Behalf Of Luc = Morin > > Sent: Thursday, January 04, 2001 4:59 AM > > To: dev...@li... > > Subject: Re: [Dev-C++] what is a resource? how do I create my own = headers? > > > > > > > > ----- Original Message ----- > > From: "Ramana Kumar" <ra...@my...> > > To: <dev...@li...> > > Sent: Wednesday, January 03, 2001 9:16 PM > > Subject: RE: [Dev-C++] what is a resource? how do I create my own = headers? > > > > > > > > > > As far as I know, this is how you use header files, this is how > > I use them > > > but sometimes I don't see the point if you know the function will = not be > > > used later. If this is the case, keep the whole function in one > > file (a .h > > > file if it happens to be) and then you can include this as a > > file full of > > > functions in a project (used in a .cpp file like main.cpp). > > > > > > Ramana Kumar > > > ICQ# 93667117 > > > To get paid for surfing the 'net please visit > > > https://www.alladvantage.com/joinsecure.asp?refid=3Djpn471 > > > > > > > It is not a very good idea to put definitions in a header file. Next = thing > > you know, > > you include the file from another translation unit and you get = multiple > > definitions > > problems. > > > > I'd advise that if the function is gonna be used only in one = translation > > unit to put > > the function in that very same translation unit (declaration AND > > definition). > > > > Just my $0.02 > > > > Luc Morin > > > > > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users > > >=20 >=20 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users |
|
From: Ioannis V. <no...@ya...> - 2001-01-04 15:00:51
|
Well, one can write the functions declarations in one .h file e.g. magic.h
so as the user (programmer) sees them, and the implementations in a .c (or
.cpp) file .e.g. magic.c and place an #include "magic.c" line at the end of
the header file. Or he can place the implementations too with (or without)
the functions' declarations.
So in the program he can directly use #include "magic.h" .
E.g. a function:
void tweety(void)
{
printf("\nI think thhat i see a caty\n");
}
a) In magic.h:
void tweety(void); // The user interface. The interface which another user
sees without bothering
// with implemetation details
#include magic.c
-----------------------
In magic.c:
#include <stdio.h>
void tweety(void)
{
printf("\nI think that i see a caty\n");
}
b) In magic.h:
void tweety(void); // The user interface. The interface which another user
sees without bothering
// with implemetation details
// Here the implementation begins. User interface and implementation on the
same file
#include <stdio.h>
void tweety(void)
{
printf("\nI think that i see a caty\n");
}
c) magic.h:
// implementation only. The user must scroll through implementation details
to discover the user interface.
// NOT recommended.
#include <stdio.h>
void tweety(void)
{
printf("\nI think that i see a caty\n");
}
----------------------------------------------------------------------------
-----------------------------------------------------
The main point here is that where you place an #include preprocessor
command, is the same as if you typed the contents of the file you #included
in that place. One can #include whattever file he wants, e.g. #include
"test.txt".
Most compilers have an automation feature that when you #include a header
file, it #includes the corresponding .c or .cpp file, but do not rely on
automations.
Ioannis
|
|
From: Ioannis V. <no...@ya...> - 2001-01-04 14:40:40
|
See my own header file: http://members.nbci.com/noicys/source_code/merlin.h I do not know about the resource stuff. Ioannis > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...]On Behalf Of Alan Thomas > Sent: Thursday, January 04, 2001 3:46 AM > To: dev...@li... > Subject: [Dev-C++] what is a resource? how do I create my own headers? > Importance: High > > > Two questions: > > (a) What is a "resource" file? Is it relevant for a [DOS] > console program? > Where is it documented what to do with a resource file? > > I created a new project (console application) and added three > existing files (two cpp{one with a main function, another with other > functions} and one header file. Asked it to Compile the project, but it > gave me an error with the resources ("no resources"). Tried again with a > new, empty project. Added files but got same error when I attempted to > compile. > > (b) How do I save/use a header file? > > I have some functions. Wrote and tested them. Took the function > prototypes and #includes, and made them the header file. Included it > (#include "html.h") in my file with the main function. Took the rest --- > the function definitions --- and made them the .cpp file. Is this the way > you use a header file? > > Where is this documented or described? > > Thanks, Alan > > > > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users > |