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 support@ccsinfo.com

Code generates 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

Code generates errors!
PostPosted: Sun Oct 12, 2008 7:55 pm     Reply with quote

Hello,

Can someone tell me why the following code fragment generates errors?
Basically I am passing a pointer of struct type by reference to a function!
Code:
#include <Dv4685.h>           
#include <stdlib.h>             
#include <stdlibm.h>         
#include <MATH.H>         

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

typedef struct passCode {
int TOUCHES;
int LEAST_X;
int FAR_X;
int LEAST_Y;
int FAR_Y;
int DISP_INTRVL;
int MSG_NUM;
} PASSCODE;

void ULC_PASSC_config_passcode (enum_OBJTASK OBJ_CNTRL,
PASSCODE **obj_PASSCODE,
int TOUCHES,
int ID_LEAST_X,
int ID_FAR_X,
int ID_LEAST_Y,
int ID_FAR_Y,
int DISP_INTERVAL,
int MSG_NUM)
{
switch (OBJ_CNTRL)
{
case e_CREATE:
*obj_PASSCODE = (PASSCODE*) malloc (sizeof (PASSCODE));

case e_MODIFY:
(*obj_PASSCODE)->TOUCHES = TOUCHES;
(*obj_PASSCODE)->LEAST_X = ID_LEAST_X;
(*obj_PASSCODE)->FAR_X = ID_FAR_X;
(*obj_PASSCODE)->LEAST_Y = ID_LEAST_Y;
(*obj_PASSCODE)->FAR_Y = ID_FAR_Y;
(*obj_PASSCODE)->DISP_INTRVL = DISP_INTERVAL;
(*obj_PASSCODE)->MSG_NUM = MSG_NUM;
break;

case e_FREE:
free(*obj_PASSCODE);
*obj_PASSCODE = NULL;
break;
}
}

void main()
{
PASSCODE *obj_PASSCODE; // CREATE A passCode POINTER

ULC_PASSC_config_passcode(e_CREATE, &obj_PASSCODE, 4,0,0,0,0,0,0);
ULC_PASSC_config_passcode(e_FREE, &obj_PASSCODE, 0,0,0,0,0,0,0);
}

If you just copy the above code and compile you can see how errors will occur.

All help appreciated!

Best regards
Robert
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Oct 13, 2008 12:00 am     Reply with quote

Hello,

please also tell the compiler type and version.

However, I also experienced problems of CCS C to understand double indirection, thus I had to recode some functions used since years with various C compilers. The below version, with should be equivalent to your code, is accepted by PCD V4.079, but I didn't check for correct operation.

Code:
typedef struct passCode {
int TOUCHES;
int LEAST_X;
int FAR_X;
int LEAST_Y;
int FAR_Y;
int DISP_INTRVL;
int MSG_NUM;
} PASSCODE, *PPASSCODE;

void ULC_PASSC_config_passcode (enum_OBJTASK OBJ_CNTRL,
PPASSCODE *obj_PASSCODE,
int TOUCHES,
int ID_LEAST_X,
int ID_FAR_X,
int ID_LEAST_Y,
int ID_FAR_Y,
int DISP_INTERVAL,
int MSG_NUM)
{
PPASSCODE opc;
switch (OBJ_CNTRL)
{
case e_CREATE:
*obj_PASSCODE = (PPASSCODE) malloc (sizeof (PASSCODE));
opc = *obj_PASSCODE;

case e_MODIFY:
opc->TOUCHES = TOUCHES;
opc->LEAST_X = ID_LEAST_X;
opc->FAR_X = ID_FAR_X;
opc->LEAST_Y = ID_LEAST_Y;
opc->FAR_Y = ID_FAR_Y;
opc->DISP_INTRVL = DISP_INTERVAL;
opc->MSG_NUM = MSG_NUM;
break;

case e_FREE:

free(*obj_PASSCODE);
*obj_PASSCODE = NULL;
break;
}
}

void main()
{
PPASSCODE obj_PASSCODE; // CREATE A passCode POINTER

ULC_PASSC_config_passcode(e_CREATE, &obj_PASSCODE, 4,0,0,0,0,0,0);
ULC_PASSC_config_passcode(e_FREE, &obj_PASSCODE, 0,0,0,0,0,0,0);
}


Regards,
Frank
Hello FvM
Guest







PostPosted: Tue Oct 14, 2008 2:41 pm     Reply with quote

Thanks for your post,

I will try to see if CCS comes up with a fix. I was really hoping to use multiple indirection (**).

Or else, I will use your way, which I am sure it works.

I don't understand why CCS compiler has these issues?

Anyways, I thank you very much for your post, much appreciated!

Regards
Roberto
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