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

Compiler error

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



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

Compiler error
PostPosted: Fri May 20, 2005 9:37 am     Reply with quote

Float Vbat;
int floatgrootte = sizeof(Vbat);

? Why do I get an error ?

I want to get the size of a float (should return '4' bytes)


thx
valemike
Guest







PostPosted: Fri May 20, 2005 12:04 pm     Reply with quote

I'm pretty sure that
sizeof(float) will work.

or if you have

struct mystruct
{
...
...
};

you can do a sizeof(mystruct) i think.

i guess its a c syntax thing. since i don't have a k&r book in front of me, i can't tell you for sure.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 20, 2005 12:47 pm     Reply with quote

Christophe, the answer is "go simple", and "make a test program".
The following program displays this result: 4

Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void main()
{
int floatgrootte;
float Vbat;

floatgrootte = sizeof(Vbat);

printf("%d", floatgrootte);

while(1);
}
Ttelmah
Guest







PostPosted: Fri May 20, 2005 2:18 pm     Reply with quote

I think the problem is between the difference in 'runtime' code, and 'compile time' code. Sizeof(Vbat), requires that the variable 'Vbat' actually exists (which is not true at 'compile time'), while 'Sizeof(float)', only requires the understanding of the data type. Sizeof(Vbat), will work fine at runtime (as PCM programmer points out).
So the two choices are:
1)
Code:

Float Vbat;
int floatgrootte = sizeof(Float);


or 2):
Code:

Float Vbat;
int floatgrootte;
floatgroote = sizeof(Vbat);


The second evaluates 'sizeof', at runtime, rather than at compile time, and again will work.

Best Wishes
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