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

Forwards declaration Problem???

 
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

Forwards declaration Problem???
PostPosted: Tue Jan 06, 2009 7:54 pm     Reply with quote

Hello,

I am using PCW Version 4.083

The following code has been tested in VC++ and works without any errors. However in PCW compiler I get an error saying that it is expecting a "{" at the forwards declaration line?????

Can someone please consider the following code:
Code:
#include <18f4685.h>
#device  *=16
#device  ADC=8             //Analogs
#device  ICD=TRUE
#case                           //TURNS ON CASE SENSITIVITY IN CODE

#fuses   HS,NOLVP,NOWDT,PUT
#use     delay(clock=40M, oscillator=10M)
#fuses   H4

#include <stdlib.h>              // CCS LIBRARY STANDARD LIBRARY

typedef long *LR;
typedef long WPARAM;
typedef long LPARAM;

struct tagWnd; // forward declaration    <<< error points here ????

typedef struct tagHwnd{
struct tagWnd *handle;
} HWND;

typedef LR (*WNDPROC)(HWND, long, int, int);

typedef struct tagWnd{   
WNDPROC  lpfnWndProc;
int      style;
long     backGround;
long     titleMsg;
long     extra;
} WND, *pWND;

//CALLBACK FUNCTION
LR callerFunction(LR(*WNDPROC)(HWND, long, int, int) ,HWND h, long m, int w, int l);

LR KWP(HWND x, long m, int w, int l);

int main()
{
return 0;
}

Thankyou all for your feedback.

Robert
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 06, 2009 9:14 pm     Reply with quote

See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?p=101183
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Tue Jan 06, 2009 9:14 pm     Reply with quote

CCS C is not C++. I'm not familiar with how you are defining your structure, but it does not look correct. DL the manual and take a look at page 39. Below is a clip from that page in how to define a structure.

Code:
struct data_record {
int a [2];
int b : 2; /*2 bits */
int c : 3; /*3 bits*/
int d;
}data_var;


Others on the forum may be able to help more with this. Good luck.
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
Cont
Guest







Cont
PostPosted: Tue Jan 06, 2009 10:22 pm     Reply with quote

Hello PCM,

Are you saying that PCW does not support forwards declarations. Simply compiling this as a .c file in VC++ compiles without errors.

It seems that in C, doing a forward declaration is pretty common... like this:
======================
struct tagWnd; // forward declaration <<< error points here ????

typedef struct tagHwnd{
struct tagWnd *handle;
} HWND;

typedef struct tagWnd{
WNDPROC lpfnWndProc;
int style;
long backGround;
long titleMsg;
long extra;
} WND, *pWND;
===================================

Unfortunately I don't see a resolution from the link you posted. Sorry!

I am looking to know what I should modify in my code in order to make the forwards declaration work.

Please get back with any other advice. Your help is much appreciated!

Confused!

Robert
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Jan 06, 2009 10:59 pm     Reply with quote

Again,

Don't think C is C++.

Even more important,

NEVER think C on a microcontroller is going to be the same as C for a full blown OS. (like gcc or any MS big-os product).

So to answer your question: Yes, VC++ might compile that just fine.

But it's not C.

And it's not C on an 8bit microcontroller.

Look at the section in the manual again. It's quite clear about how to define structures.

Regards,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Jan 06, 2009 11:16 pm     Reply with quote

Thanks bkamen and so now I add my two cents worth..

As was said earlier CCS is an embedded compiler. It is NOT considered (or intended) to be fully ANSI compliant. The CCS compiler is also less than 1/10th the size of VC++ and runs on a much less capable processor with a Harvard architecture.

CCS DOES accept forward declarations of procedures because I do it all the time. However, since it is not C++ it does not accept forward declaration of STRUCTS. When I encountered this a few years ago I just accepted it and moved on by reordering my declarations.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Jan 06, 2009 11:22 pm     Reply with quote

Amen brother.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
rougie



Joined: 14 Jun 2006
Posts: 31

View user's profile Send private message

PostPosted: Wed Jan 07, 2009 2:35 pm     Reply with quote

>Look at the section in the manual again. It's quite clear about how to >define structures.

Which manual? I have the PIC Reference manual and the PIC micro by Nigel Gardner?????

If its one of these is there a page #?

Robert
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Wed Jan 07, 2009 2:47 pm     Reply with quote

See my original reply to you. CCS manual, page 39.
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
Guest








PostPosted: Fri Jan 09, 2009 1:40 pm     Reply with quote

I have two books related to CCS:

1-The ref manual
2-The exercise book

and I have a manual called "Pic Micro" from Nigel Gardner !

None of which correlate my issue to p.39.

The rest of my C books have nothing to do with CCS.

Anyways defining the structure as shown below and then type casting any accessing operations to the handle pointer gets rid of the error:

Code:
typedef struct tagHwnd{
void *handle;
} HWND;


This is all I was looking for: Amen!

However, there is yet another issue with function pointers which I rather discuss it with CCS directly!

Thanks all for your suggestions!

Regards
Robert
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Jan 09, 2009 4:43 pm     Reply with quote

Quote:
None of which corolate my issue to p.39.
You possibly didn't understood it has an answer to your question, but ECACE simply mentioned the struct syntax definition in the CCS pdf manual. Although it's pdf page 51, it has a printed page number 39. As previously discussed, a struct declaration body (component list) is apparently required with CCS C. Thus your circular definition requiring a forward tag definition doesn't work.

If I understand right, ANSI C99 basically provides a forward reference for structs, so it's not wrong to expect it with CCS C, but as said, embedded compiler usually have limitations.

I think, it can be done - less smart - by using an untypified pointer in the primary struct definition, that can be type casted later in ther code. I just realized, you already did.
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