NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » warning: initialization makes integer from pointer...

January 10, 2013
by keith712
keith712's Avatar

i'm slowly learning c and i've run into something interresting that i don't understand.

my compiler gives the following warning:

  LCD_driver_01.c:294:16: warning: initialization makes integer from pointer without a cast [enabled by default]

for every line like:

  char B="B";

in all the functions in my program (including main())

i also get this warning:

  LCD_driver_01.c:234:3: warning: 'pin_value' may be used uninitialized in this function [-Wuninitialized]

for the line:

  uint_8 pin_value;

pin_value is the variable being returned from a function to main()

the interresting thing is that if i recompile the program after making a change all the warnings disappear!!!

what gives?

January 10, 2013
by pcbolt
pcbolt's Avatar

keith -

Try

char B = 'B';

And

uint_8 pin_value = 0;

I'm guessing you have an "if" statement in your function that may or may not assign 'pin_value' to some value. The compiler should assign 'pin_value' to 0 if you don't assign it to anything when you declare it. But if for some wild reason it did not, you wouldn't be certain what got returned from your function.

January 10, 2013
by keith712
keith712's Avatar

thanks as always... all the warnings disappeared when i made the changes you suggested... you're exactly right: pin_value is assigned a value in an if-else if-else block... and because i'm a refugee from Python i didn't even think there might be a difference between "B" and 'B'... a little knowledge can be dangerous... keith

Post a Reply

Please log in to post a reply.

Did you know that you can control multiple LEDs from one microcontroller output? Learn more...