8 years, 11 months ago.

LPC1768 not update variables

Hi community! I have this code:

include the mbed library with this snippet

int Type;
int DutyCycle;
float Factor;
float Frequency;
float Amplitude;


int main() 
{
    Dbg.printf("Type: %d",&Type);
    Dbg.printf("Duty cycle: %d",&DutyCycle);
    Dbg.printf("Factor: %.2f",&Factor);
    Dbg.printf("Frequency: %.2f",&Frequency);
    Dbg.printf("Amplitude: %.2f\n",&Amplitude);
    Type = 0;
    DutyCycle = 0;
    Factor = 0.0;
    Frequency = 0.0;
    Amplitude = 0.0;
    Dbg.printf("Type: %d",&Type);
    Dbg.printf("Duty cycle: %d",&DutyCycle);
    Dbg.printf("Factor: %.2f",&Factor);
    Dbg.printf("Frequency: %.2f",&Frequency);
    Dbg.printf("Amplitude: %.2f\n",&Amplitude);  
    ...

When I launch the firmware and TeraTerm for diagnose the values aren't zero but the int values are at the maximum integer value why?

I have tried to initialized variables on declaration but the result is the same

posted by Davide Luongo 14 May 2015

Hi Davide, Remove the '&' from the variable names The '&' would tell the Compiler to print out the ADDRESS of the variable not the contents of the address that is the data that you wish to retreive. This is true for all C compilers

Regards Martin

posted by Martin Simpson 14 May 2015

1 Answer

8 years, 11 months ago.

Dbg.printf("Type: %d",&Type);

Why are you using & ? You know that it denotes an address in memory of a variable.

Ooooh! I haven't sede that!

posted by Davide Luongo 18 May 2015