# Hi-Tech C Compiler Error

Status
Not open for further replies.

#### 5uco

##### Member
Why do I compile a bit of code, get loads of errors, build the same code immediately afterwards, and it builds with no errors?

I can then load that code into a PIC (16F819) and it works OK.

New to Hi-Tech C, or any other C for that matter.

Seem to have seen this referenced on some forum, but there's so many I can't find it again.

Surely if the code is wrong, it's wrong for all eternity?

D.

#### Pommie

##### Well-Known Member
Some code and errors could be useful.

Mike.

#### be80be

##### Well-Known Member
Pommie you have your crystal ball working ? Mine just stopped

Would be nice to see something LOL

#### 5uco

##### Member
Lucky it's only your crystal ball not working

The code does nothing I know. Deleted most of it, still leaving error.

So, build was OK. Put in the last comment. Build gave error shown. build again, OK.

First time I've used tags. hope it works...

EDIT Start_up line 49, IF on lines 51, 52,

D.

Code:
#include		<htc.h>

__CONFIG(0x3F10);

#define		run_sw		RA1;
#define		dir_sw		RA2;

int		ctr1			=	0;
int		ctr2			=	0;
int		turns		=	0;

char	st_a_ph		=	1;
char	st_b_ph		=	1;

// ******************************************

char	sta_ph_1	=	0x0A;
char	sta_ph_2	=	0x09;
char	sta_ph_3	=	0x05;
char	sta_ph_4	=	0x06;

char	stb_ph_1	=	0xA0;
char	stb_ph_2	=	0x90;
char	stb_ph_3	=	0x50;
char	stb_ph_4	=	0x60;

// **************************************

// *********************************************

char	rate		=	0;
char	b_image	=	0;

void	main ()

{

// set up sfr's here

start_up:

if	(run_sw  ==	0) 	goto	start_up;
if	(run_sw  ==	1)	goto	start_up;

// Comment

}

#### Attachments

• HTC error.JPG
66 KB · Views: 140
Last edited:

#### xpi0t0s

##### Member
Your #define statements are wrong. #define run_sw RA1; defines run_sw as RA1; (*with* the semicolon) whereas presumably you want it defined just as RA1. #define statements are not terminated with a semicolon but with an end of line (hence the need to put a \ at the end of each line of a multi-line #define).

So
Code:
if	(run_sw  ==	0) 	goto	start_up;
will be translated as
Code:
if	(RA1;  ==	0) 	goto	start_up;

which is incorrect syntax and the errors are pretty much what I'd expect to see from any compiler. This doesn't explain why the compiler appears to compile the program successfully a second time though. A compiler bug perhaps? But it's anyone's guess what code it's producing.

#### 5uco

##### Member
Your #define statements are wrong. #define run_sw RA1; defines run_sw as RA1; (*with* the semicolon) whereas presumably you want it defined just as RA1. #define statements are not terminated with a semicolon but with an end of line (hence the need to put a \ at the end of each line of a multi-line #define).

So
Code:
if	(run_sw  ==	0) 	goto	start_up;
will be translated as
Code:
if	(RA1;  ==	0) 	goto	start_up;

which is incorrect syntax and the errors are pretty much what I'd expect to see from any compiler. This doesn't explain why the compiler appears to compile the program successfully a second time though. A compiler bug perhaps? But it's anyone's guess what code it's producing.

Did actually get it sorted, but did not put a \ at end of each line.

Put:

#define run_sw PORTA, 1
#define dir_sw PORTA, 2

That seemed to work OK. But still got errors. So, copied the original, non-truncated, code to Wordpad, created a new project, pasted the text in, and no more errors. At least, not those.

It appears the project got corrupted in some way.

Now been stuffed into a 16F819, and it seems to do what I require.

I will have to look into the \ on the end.

Thank you for the response.

D.

#### xpi0t0s

##### Member
The bit about the backslash applies only to multiline defines (that's defines that take several lines). They do not apply in this case, that was just an aside.

R-ing TFM shows PORTA,1 is special compiler syntax for bit 1 of PORTA
HI-TECH C Compiler for PIC10/12/16 MCUs v9.80 User Guide
This is non-standard C, so "if (PORTA,1==1)" in standard C will always evaluate TRUE due to the comma operator and 1==1 being always TRUE.

Last edited:

#### Noggin

##### Member
Why do I compile a bit of code, get loads of errors, build the same code immediately afterwards, and it builds with no errors?

I can then load that code into a PIC (16F819) and it works OK.

I've seen this with Hi-Tech PIC18 compiler many times. The reason it "works OK" is because I believe it is used previously compiled code (object code) from when you had something that would compile earlier. Because of this problem with the compiler, you should always use the rebuild all button.

#### 5uco

##### Member
Thanks for the replys. Will have some more attempts at this stuff later. Due to family issues will have to park Hi-Tech C for a few weeks now ..

D.

Status
Not open for further replies.

Replies
2
Views
2K
Replies
5
Views
2K
Replies
6
Views
1K
Replies
3
Views
908
Replies
17
Views
11K