cancel
Showing results for 
Search instead for 
Did you mean: 

Boolean type in C

delser9
Associate II
Posted on March 11, 2004 at 03:18

Boolean type in C

7 REPLIES 7
delser9
Associate II
Posted on March 09, 2004 at 03:49

Hello all!

We use the 'STDTYPES.H' from Hiware. The boolean variable is defined as follows:

typedef int Bool;

define TRUE 1

define FALSE 0

Our program works well with that definition. But in order to have smaller code size we changed the boolean to 'char' datatype:

typedef char Bool;

define TRUE 1

define FALSE 0

Unfortunately, now the program doesn't work correctly anymore. Has anyone a clue what is wrong with that?

Thank you for your help!

Alfredo

sjo
Associate II
Posted on March 09, 2004 at 10:14

Remember that if you modify anything from the standard libs then I would guess you also have to rebuild the libraries.

You would be using char type the libs using int.

Why don't you just define your own type eg.

#define BOOL char;

then this will not have an affect on the libs.

I tend to use cosmic which has native support for bool

Just a thought.

Regards

sjo

[ This message was edited by: sjo on 09-03-2004 15:05 ]
kr
Associate II
Posted on March 10, 2004 at 00:48

Just to add a few points on how to use BOOL kind of variables to reduce your code size.

#pragma DATA_SEG SHORT ZEROPAGE

struct

{

unsigned int bit0:1;

unsigned int bit1:1;

unsigned int bit2:1;

}BitVar;

#pragma DATA_SEG DEFAULT

BitVar.bit0 = 1; will produce BSET BitVar,#0

Hope this will be useful.

--krsel

delser9
Associate II
Posted on March 10, 2004 at 05:54

Dear sjo,

thanks for your hints. I tried to do it without the library. It showed the same problem. 'Int' is working but not 'char'.

Something I don't understand at all is that although I never include the library 'stdtypes.h' it is known by the compiler. I can say that because memory use is greatly reduced when I change from int to char in the library file.

Do you have any idea what is going wrong here?

Greetings

Al
delser9
Associate II
Posted on March 10, 2004 at 06:01

Dear krsel,

thank you for help. I do not yet understand what you wrote. I find it quite difficult to find any sound information about '#pragma' and 'ZEROPAGE' and all that stuff. As long as its only the C-stuff you can find heaps of it on the web. But about the compiler it's very difficult. Do you have any source where these things are explained?

Do you have other similar hints to reduce code size?

Greetings,

Al

delser9
Associate II
Posted on March 10, 2004 at 09:39

Dear sjo,

I found it. The stdtypes are included in the 'ST7FLITE29.h' library which describes the I/O registers of the mcu.

Al
kr
Associate II
Posted on March 11, 2004 at 03:18

Hi Al,

The stuffs which i mentioned here is an replacement for BOOL variables which will aso reduce the code size considerably.

It can also be used for declaring & defining a bit variables. In fact this is very convenient way to allocate the RAM area, zero page or long range by means of #pragma directives. If you find a better solution pease leave it, this is just to have an idea.

--Krsel