Re: C Question: TypeDefing a structure ?
Hello Giovanni,
Thankyou guys for your replies, I don't understand why I never had problems
with other structures when implemented this way... I did this with four other
structures without any problems.
Anyways, I have to include the <API_DDLB_LIB.c> file in the ACM152.c file or
else I get the following error:
"Function used but not defined ... ULC_DDLB_LIB_config_DDLB SCR=4341"
No, I think you should do:
extern DDLB * obj_DDLB;
in the header.
In some .c file define that variable globally
You mean like this:
==============================================ACM152.h
enum OBJECTTASK {e_CREATE=1, e_MODIFY, e_FREE};
==============================================ACM152.c
#include <ACM152.h>
#include <API_DDLB_LIB.h>
#include <API_DDLB_LIB.c>
DDLB *obj_DDLB; //Declared in a .c file !!!!!!!!
void main()
{
obj_DDLB = ULC_DDLB_LIB_config_DDLB (e_CREATE, 0);
ULC_DDLB_LIB_do_DDLB(obj_DDLB);
ULC_DDLB_LIB_config_DDLB (e_FREE, 0);
}
==========================================API_DDLB_LIB.h
typedef struct ddListBox{
long CURR_ICON_NUM;
} DDLB;
extern DDLB *obj_DDLB;
DDLB* ULC_DDLB_LIB_config_DDLB
( int OBJECT_CONTROL,
long CURR_ICON_NUM);
void ULC_DDLB_LIB_do_DDLB (DDLB *obj_DDLB);
==========================================API_DDLB_LIB.c
DDLB* ULC_DDLB_LIB_config_DDLB(
int OBJECT_CONTROL,
long CURR_ICON_NUM)
{
switch (OBJECT_CONTROL)
{
case e_CREATE:
obj_DDBL = (DDLB*) malloc (sizeof (struct ddListBox));
case e_MODIFY:
obj_DDBL->CURR_ICON_NUM= CURR_ICON_NUM;
return obj_DDBL;
break;
case e_FREE:
free(obj_DDBL);
break;
}
}
void ULC_DDLB_LIB_do_DDLB( DDLB *obj_DDLB)
{//NO CODE }
===================================================
Sorry Giovanni, unfortunately, still no luck!
Hello, Igor. I was told to include the header files seperately and not to
include header files in their associated .c files. For example I was taught
not to do this:
=====main.c
#include <xxx.c>
code....
=========
======xxx.h
declarations...
=========
======xxx.c
#include <xxx.h>
code...
===========
rather I was taught to do this:
=====main.c
#include <xxx.h>
#include <xxx.c>
code....
=========
======xxx.h
declarations...
=========
======xxx.c
code....
===========
Now if this is not right, I guess I am getting critisized which ever way I
try it !!!
Explain me something. Whats wrong with having your main .c file include all
the header files that contain declarations for their respective .c files? In
other words will this strategy of including header files lead to some
catastrophic problems later on as the program evolves ?
Yes, you are right API_DDLB_LIB.c gives errors as shown in innitial post.
--
Best regards
Robert
"Giovanni Dicanio" wrote:
"Robby" <Robby@discussions.microsoft.com> ha scritto nel messaggio
news:8FD11D01-4D18-476F-81AC-CFF86AE07F26@microsoft.com...
How can this be when "obj_DDLB" is declared globally?????
In pure C, I think you should use an "extern" in some header file to
*declare* that variable globally.
Then, in some .C file, you should *define* that variable globally.
==============================================ACM152.c
#include <ACM152.h>
#include <API_DDLB_LIB.h>
#include <API_DDLB_LIB.c>
Are you sure you want to #include a .c file??
Usually you should #include only .h header files...
==========================================API_DDLB_LIB.h
typedef struct ddListBox{
long CURR_ICON_NUM;
} DDLB;
DDLB *obj_DDLB;
No, I think you should do:
extern DDLB * obj_DDLB;
in the header.
In some .c file define that variable globally.
HTH,
Giovanni