473,473 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

printf on alcohol

Has anybody ever seen a thing like this?

### code:

double link_bw_cost(int a, int b){

double ro;

ro = ( (double) link_usage[a][b].bandw / (double) link[a][b].bandw);

printf("DEBUG - a = %d e b = %d\n", a, b);
printf("DEBUG - link_usage[%d][%d].bandw = %ld link[%d][%d].bandw
= %ld \n", a, b, link_usage[a][b].bandw, a, b, link[a][b].bandw);
### when running:

DEBUG - a = 0 e b = 2
DEBUG - link_usage[0][2].bandw = 0 link[1078689792][0].bandw = 2

Oct 18 '07 #1
4 1355
In article <11**********************@q5g2000prf.googlegroups. com>,
<es******@gmail.comwrote:
>Has anybody ever seen a thing like this?
>### code:
>double link_bw_cost(int a, int b){
double ro;
ro = ( (double) link_usage[a][b].bandw / (double) link[a][b].bandw);
>printf("DEBUG - a = %d e b = %d\n", a, b);
printf("DEBUG - link_usage[%d][%d].bandw = %ld link[%d][%d].bandw
= %ld \n", a, b, link_usage[a][b].bandw, a, b, link[a][b].bandw);
>### when running:
>DEBUG - a = 0 e b = 2
DEBUG - link_usage[0][2].bandw = 0 link[1078689792][0].bandw = 2
Yes, I've seen things like that when link_usage[a][b].bandw is wider
than a long (%ld). You didn't happen to supply us with the structure
definition, so we can't tell for sure.

--
"I will speculate that [...] applications [...] could actually see a
performance boost for most users by going dual-core [...] because it
is running the adware and spyware that [...] are otherwise slowing
down the single CPU that user has today" -- Herb Sutter
Oct 18 '07 #2
Bingo!

The structure member was re-defined from long int to double.

Thank you very much Walter!
On Oct 18, 8:55 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
In article <1192748632.436515.173...@q5g2000prf.googlegroups. com>,

<estan...@gmail.comwrote:
Has anybody ever seen a thing like this?
### code:
double link_bw_cost(int a, int b){
double ro;
ro = ( (double) link_usage[a][b].bandw / (double) link[a][b].bandw);
printf("DEBUG - a = %d e b = %d\n", a, b);
printf("DEBUG - link_usage[%d][%d].bandw = %ld link[%d][%d].bandw
= %ld \n", a, b, link_usage[a][b].bandw, a, b, link[a][b].bandw);
### when running:
DEBUG - a = 0 e b = 2
DEBUG - link_usage[0][2].bandw = 0 link[1078689792][0].bandw = 2

Yes, I've seen things like that when link_usage[a][b].bandw is wider
than a long (%ld). You didn't happen to supply us with the structure
definition, so we can't tell for sure.

--
"I will speculate that [...] applications [...] could actually see a
performance boost for most users by going dual-core [...] because it
is running the adware and spyware that [...] are otherwise slowing
down the single CPU that user has today" -- Herb Sutter

Oct 19 '07 #3
es******@gmail.com writes:
Has anybody ever seen a thing like this?

### code:

double link_bw_cost(int a, int b){

double ro;

ro = ( (double) link_usage[a][b].bandw / (double) link[a][b].bandw);

printf("DEBUG - a = %d e b = %d\n", a, b);
printf("DEBUG - link_usage[%d][%d].bandw = %ld link[%d][%d].bandw
= %ld \n", a, b, link_usage[a][b].bandw, a, b, link[a][b].bandw);
### when running:

DEBUG - a = 0 e b = 2
DEBUG - link_usage[0][2].bandw = 0 link[1078689792][0].bandw = 2
It's helpful to tell us what you think is wrong with the output,
though it's obvious enough in this case (the value of ``a'' is shown
as 0 and as 1078689792 in the same printf call).

Here's the final printf statement reformatted with comments added; the
comments indicate which format specifier is used for each argument.

printf("DEBUG - link_usage[%d][%d].bandw = %ld "
"link[%d][%d].bandw = %ld \n",
a, /* %d */
b, /* %d */
link_usage[a][b].bandw, /* %ld */
a, /* %d */
b, /* %d */
link[a][b].bandw); /* %ld */

We know that a and b are of type int, but we don't know the type of
bandw. (I'm assuming that link_usage[a][b] and link[a][b] are of the
same type, and therefore that both bandw are of the same type, but I
can't even be sure of that.)

The printf statement assumes that bandw is of type long int. The most
likely explanation for the misbehavior is that bandw is actually of
some other type. Using an incorrect printf format causes undefined
behavior.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Oct 19 '07 #4
es******@gmail.com wrote:
Bingo!
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>
Oct 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: aditya | last post by:
hi, Can anybody please tell me that how the following printf(...) statement works- main(){ int d=9; printf("%d",printf("%d")); return 0;
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
4
by: pai | last post by:
Hi , Can any one tell me how this statement of printf is behaving . how the last digit is printed int a=2,b=4,c=7; printf("%d",printf("%d %d:",a,b)); //answer to this was 2 4:3
11
by: timmu | last post by:
Someone asked me a question about integer division and printf yesterday, I tell him he should do a casting to float/double before you do any interger division. But he doesn't think so, so I try...
34
by: Old Wolf | last post by:
Is there any possible situation for printf where %hd causes a different result to %d, and the corresponding argument was of type 'short int' ?
1
by: linq936 | last post by:
Hi, I read in many places that the string to be outputted by printf() must be ending with newline, for example, it should be printf("Hello World.\n"); instead of printf("Hello World.");
4
by: fdecker | last post by:
I want to develop an application that does what daemon tools and alcohol 120% does. Could anyone direct me on a path in that direction? Like steps of what I will need and what I will have to do....
0
by: ch612bunn | last post by:
Alcohol 120% 1.9.6.5429 crack
0
by: stutler.jil | last post by:
Alcohol 1.9.6.5429 crack
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.