Re: [Dev-C++] Split code in public/private parts - Help please
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-01-11 11:41:12
|
A library is a collection of multiple object files. There are a lot of
good references out there.
If any other object file must call your functions, you might do
/* private_include_file.h */
#define eval_area get_lost_1
#define solve_root get_lost_2
...
and then your code will be
#include "private_include_file.h"
void my_callable_function(void) {
...
if (eval_area(1,2,3) > 0) {
solve_root(4,5,6);
}
}
If your variables and functions doesn't need to be accessed from the
outside, it is enough to declare them static, i.e.:
/* my_private_file.c */
static int private_variable_1;
static float private_variable_2;
char public_version[] = "My callable module version 1.02.01";
static int eval_area(int a,int b,int c) {
....
return a+b+c;
}
void my_callable_function(void) {
...
if (eval-area(1,2,3) > 0) {
solve_root(4,5,6);
}
}
/Per W
On Sun, 11 Jan 2004, Jean-Marc Godart wrote:
> Thanks a lot for your very adequate answer, Ferdinando.
>
> I have two extra questions, based on your answer ... Sorry it is a little
> off-topic now since it is more like a general C question.
>
> (1) What is the difference between a ".o" file and a ".lib" file (library)
> and how can I convert one in the other ?
>
> (2) I understand it is not possible to prevent someone from calling all of
> the functions in the ".o" file. Yet, I just noticed the names of all my
> variables and functions appear "in clear" in the code of the ".o" file (when
> opening it with a text processor). Is there a way to avoid this (as the
> names are explicit and give hints about the way the program works) ? Of
> course, I can just give names as "a", "b", "c"... but then I get lost in my
> source code. I tried to use "static" but it does not change a thing ...
>
> Any help is welcome !
>
> Thanks again,
>
> Jean-Marc
>
> ----- Original Message -----
> From: "Ferdinando Formica" <s2...@st...>
> To: <go...@sk...>
> Cc: "Dev-C++ Mailing List" <dev...@li...>
> Sent: Saturday, January 10, 2004 7:51 PM
> Subject: Re: [Dev-C++] Split code in public/private parts - Help please
>
>
> >
> > > How can I compile "part two" (which has no "main" function),
> > > so that the source code cannot be seen anymore ?
> >
> > You can put "part two" in a separate file, and compile it singularly, then
> > distribute the output file (with .o extension).
> >
> > > Then, how can I compile "part one" source code (which has
> > > the "main" function) with "part two" compiled version?
> >
> > You have to include in your project the .o file selecting "include in
> > link" and deselecting "include in compilation", or equivalently build a
> > library from it (a .a file), call it e.g. libp2.a, and specify "-lp2" in
> > linker options.
> >
> > > How can I make sure it is not possible
> > > to call directly another function of "part two" ?
> >
> > _Really_ you can't, but only who knows the implementation (or is a good
> > and patient reverse engineer) know what's inside an object file. You
> > should put declarations for all functions you would like a programmer to
> > call in a header (.h) and distribute it with your .o or .a file.
> >
> > Bye, Ferdinando.
> >
> >
> >
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Perforce Software.
> Perforce is the Fast Software Configuration Management System offering
> advanced branching capabilities and atomic changes on 50+ platforms.
> Free Eval! http://www.perforce.com/perforce/loadprog.html
> _______________________________________________
> 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
>
|