NO

Author Topic: The meaning of &f and debugging question  (Read 5773 times)

Roda

  • Guest
The meaning of &f and debugging question
« on: August 15, 2013, 09:41:16 PM »
Executed the following code from a book on C I'm reading:

Code: [Select]
/*Function to calculate the absolute value of a number
using the Newton-Raphson Method */

#include <stdio.h>

float absoluteValue(float x)
{
if (x < 0)
x = -x;
return (x);
}

//Function to compute the square root of a number

float squareRoot(float x)
{
const float epsilon = .00001;
float guess = 1.0;

while (absoluteValue(guess * guess - x) >= epsilon)
guess = (x / guess + guess) / 2.0;
return guess;
}

int main(void)
{
printf("squareRoot(2.0) = %f\n", squareRoot(2.0));
printf("squareRoot(144.0) = &f\n", squareRoot(144.0));
printf("squareRoot(17.5) = %f\n", squareRoot(17.5));

return 0;
}

The square root of 144.0 is showing up as &f and of course it should be 12.000000. What does "&f" mean and why is it doing that? How can I get it to display correctly?

Also, when debugging (I'm sure you get this all the time) all I can see is hex for the value of my variables. I searched and read the tutorials and followed the instructions but all I still see is hex for values. I don't know what I'm doing wrong because just a few weeks ago I followed the instructions when using the debugger and I wasn't seeing hex values but source code values. If someone can give me a link to a past post with thorough instructions I would appreciate it.


Roda

  • Guest
Re: The meaning of &f and debugging question
« Reply #1 on: August 15, 2013, 10:50:04 PM »
OK I figured out how to show source code values in the debugger in other programs but in this particular program the values for variables are showing up something like: {xmm7 = 16325798840198490}

What does this mean and why is this showing up and not just regular source code?

Roda

  • Guest
Re: The meaning of &f and debugging question
« Reply #2 on: August 15, 2013, 11:38:37 PM »
Well I feel real stupid!  ;D I'm such a noob! It was just a mistake in my code. I need rest because normally I always catch little things like that.

But the debugger is still showing values the way I previously mentioned. Can anyone explain please?

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: The meaning of &f and debugging question
« Reply #3 on: August 15, 2013, 11:58:43 PM »
Well I feel real stupid!  ;D I'm such a noob! It was just a mistake in my code. I need rest because normally I always catch little things like that.
Yup, just a little typo... ;)
Quote
But the debugger is still showing values the way I previously mentioned. Can anyone explain please?
Well, do you have the debugging option in both the compiler and the linker for the project enabled?

Ralf

Roda

  • Guest
Re: The meaning of &f and debugging question
« Reply #4 on: August 16, 2013, 01:26:29 AM »
Yes they are both enabled. Debug Information for the compiler is set to full. Debug Information for the linker is in CodeView format (I have a x64 machine).

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: The meaning of &f and debugging question
« Reply #5 on: August 16, 2013, 03:31:57 AM »
Yes they are both enabled. Debug Information for the compiler is set to full. Debug Information for the linker is in CodeView format (I have a x64 machine).
I copied your source code into a new Win32 console project, fixed the typo, set debug info to full for the compiler and CodeView&COFF in the linker and it shows the source code just fine, see attached screenshot.

Could you please zip up the project on your end and post it here, so we can take a look at it?

Ralf

Roda

  • Guest
Re: The meaning of &f and debugging question
« Reply #6 on: August 16, 2013, 06:06:38 AM »
I tried what you did with the Win 32 console project and it worked for me too. Anyways, here is the zip.

Roda

  • Guest
Re: The meaning of &f and debugging question
« Reply #7 on: August 16, 2013, 06:10:22 AM »
Here is a screenshot of the program using Win64 console project.

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: The meaning of &f and debugging question
« Reply #8 on: August 16, 2013, 09:02:54 AM »
...the values for variables are showing up something like: {xmm7 = 16325798840198490}

What does this mean and why is this showing up and not just regular source code?

It means Pelles C uses xmm7 internally for calculations. 16325798840198490 seems to be a decimal value (no abcdef..., 17 chars), and unfortunately that does not resemble any of your values. You could only see what really happens by debugging at assembly level. This can be done by building the project with compiler debug disabled and assembly debug enabled.

Right now I have no access to a 64-bit system. The 32-bit version uses the FPU, not the xmm regs, so that is a different story...

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: The meaning of &f and debugging question
« Reply #9 on: August 16, 2013, 07:57:16 PM »
I tried what you did with the Win 32 console project and it worked for me too. Anyways, here is the zip.
Ok, I kind of misread part of your initial message, I thought you see the hex/assembler code in the debugger window instead of the C course code, I kind of missed that you were referring to the variables watch window.

I am a bit busy with a data recovery job at work that is stressing me a bit more, but i will recompile this as a 64bit console app on my laptop (which is running Windows 7 Ultimate and I have actually the 64bit compiler installed, though I try to avoid using 64bit code).

Ralf

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: The meaning of &f and debugging question
« Reply #10 on: August 17, 2013, 01:17:17 PM »
You have set the full optimization so compiler uses xmm registers to calculate floats.
Try to remove optimizations in project compiler options.
the format:
Code: [Select]
<some reg>    {<value>}is the way PellesC tells you that your variable is created in a register instead of memory location. In your case the variable is in xmm6, xmm7 and xmm0 registers.
To switch between decimal and hex visualization of data you have to left click in the variables pane, you will get a dropdown menu where you can choose to visualize values as decimal or hex.
« Last Edit: August 17, 2013, 01:19:29 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Roda

  • Guest
Re: The meaning of &f and debugging question
« Reply #11 on: August 21, 2013, 06:59:23 AM »
Thanks everyone for your help and explanations. As for getting the values to show as source code I followed what frankie said about removing optimizations in project compiler options and it worked.