CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Typedefing a structure but get errors?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rougie



Joined: 14 Jun 2006
Posts: 31

View user's profile Send private message

Typedefing a structure but get errors?
PostPosted: Fri Aug 22, 2008 7:07 pm     Reply with quote

Hello,

Basically, here is what I have coded. 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. I have tried dozens of tests, but can't seem to find the source of the errors.

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 these errors be possible when "obj_DDLB" is declared globally?????

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 22, 2008 11:09 pm     Reply with quote

Can you post this as a little test program ? Add the lines for #include,
#fuses, etc. In other words, tack a new post onto this thread, in which
the above code is re-formatted into a small but complete program.
We should be able to copy and paste it into MPLAB, compile it, and
see those same error messages, with the same line numbers.
You need to make it easy for us to work on your problem.

When you post code, highlight all of it, and then punch the "Code"
button. Then preview it to make sure it looks good before you
submit it. A code block makes it easier for us to read it.

Also, tell us your compiler version. Many problems are version
dependent.
Guest








PostPosted: Sat Aug 23, 2008 1:13 am     Reply with quote

Hello PCM, and thankyou for your reply, it is ery kind of you!

Here you go!

==================="ACM152.c" Program file
Code:

#include <18f4685.h>
#device  *=16
#device  ADC=8
#device  ICD=TRUE
#fuses   HS,NOLVP,NOWDT,PUT
#use     delay(clock=40M, oscillator=10M)
#fuses   H4

//CCS LIBRARIES
#include <Dv4685.h>              //DEVICE INNITIALIZATIONS
#include <stdlib.h>              //CCS LIBRARY STANDARD LIBRARY
#include <stdlibm.h>             //CCS LIBRARY (HEAP) MALLOC MODULE
#include <MATH.H>                //CCS LIBRARY MATH MODULE

enum OBJECTTASK   {e_CREATE=1, e_MODIFY, e_FREE};   

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);

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);
}


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 }

=========================================
Regards Robert
RayJones



Joined: 20 Aug 2008
Posts: 30
Location: Melbourne, Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Aug 23, 2008 3:58 am     Reply with quote

simple typo,

you declared DDLB* obj_DDLB;

you are de-referencing obj_DDBL
ie BL not LB

BTW, you also have:
void ULC_DDLB_LIB_do_DDLB( DDLB *obj_DDLB)

This is sure to cause YOU confusion having a local variable the same name as your global.... The compiler will be happily compile though.


Cheers, Ray
Guest








Unbelievable but true!
PostPosted: Sat Aug 23, 2008 10:33 am     Reply with quote

Hello Ray,

I can't believe it that I wasted all this time for a stupid typo!

I thankyou very much my freind, it is most appreciated.

You have no idea how much watering down I had to do from the original project code to find out that it should of been LB instead of BL!

Tanks again!

With sincere regards
Robert
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group