Re: C Question: TypeDefing a structure ?
Alexander, Thankyou for your reply! And I sincereley thank everyone else for
their feedback!
Unfortunately, I tried to change the function's name and still got the same
error. Also, I tried it in VC++ .NET and got a similar error amongs others,
however here is the firts one:
c:\_DTS_PROGRAMMING\C_PROGRAMMING\Test1\Test\API_DDLB_LIB.c(9) : error
C2065: 'obj_DDBL' : undeclared identifier
So now I am convinced that I am doing something wrong since both compilers
are giving me the same error. I am researching all the examples that I can
and I always find code samples like this:
===========================
typedef struct {
float real;
float imaginary; } complex;
complex x, *y, a[100];
===========================
which are very similar to mine in terms of declaration. However, I think the
problem has to do more with the fact that I am mallocing and freeing memory
allocated by a global pointer of type DDLB bywhich is all done within the
"ULC_DDLB_LIB_config_DDLB" function!!!!
If I would of known that there are so many variances and wrinkles when it
comes to structures and the heap, I would of innitially spent atleast 1 year
just on structures and allocations. I am not happy with myself! Although I
have learnt structures, pointers to structures, arrays of structures, arrays
of pointers that point to structures and look, I still have problems!
Because there is obviously much more to know!
I deeply need any help that can be thrown my way and sincerely welcome all
feedback regarding this issue. I don't what else to try! :(
discouraged
Robert
"Alexander Grigoriev" wrote:
My guess is that your unnamed C compiler gets confused by the argument name
in ULC_DDLB_LIB_do_DDLB function declaration.
"Robby" <Robby@discussions.microsoft.com> wrote in message
news:8FD11D01-4D18-476F-81AC-CFF86AE07F26@microsoft.com...
Hello,
I have recently created my own way of manipulating the informations in a
structure and has worked very well.... until today! I am sure many
individuals had this idea and at one point or another tried this or even
adopted it.. it really is a no brainer.
I don't know... perhaps this is not the way to do things, however, it did
work for several structures in my project but this last structure has
generated errors. I have tried dozens of tests, but can't seem to find the
source of the errors. The other four structures in my project (not shown
here, however are an exact carbon copy only different names) are
manipulated
this way and are flawless in terms of functionality, errors or warning
messages.
Basically, I typedef a structure and create a global pointer of the that
type (which is of the structure's type) and then when I want to create an
object of that structure, I fecth a function which creates the object on
the
heap using malloc. The function accepts an object command parameter which
tells how the logic in the function is to be executed. Basically the
function
either creates, modifies or frees the object's data.
The errors that are generated are:
Line 10 (16,24) Unidefined identifier obj_DDLB
Line 13 ( 7,15) Unidefined identifier obj_DDLB
Line 14 (14,22) Unidefined identifier obj_DDLB
Line 18 (12,20) Unidefined identifier obj_DDLB
How can this be when "obj_DDLB" is declared globally?????
These are the errors that my MCU's compiler generates.
Thanking everyone in advance as all feedback and help is very, very
appreciated!
Here is the sample code:
==============================================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>
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;
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 }
===================================================
--
Best regards
Robert