Jump to content

Wikipedia:Reference desk/Archives/Computing/2012 November 28

From Wikipedia, the free encyclopedia
Computing desk
< November 27 << Oct | November | Dec >> November 29 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


November 28

[edit]

c puzzle

[edit]

Hi ! see the below two programmes.


Programme1:

#include<stdio.h>
#include<conio.h>
void main()
{
int x=20;
float f=20.123;
clrscr();
printf("%f",x);
getch();
}

out put:

0.000000

Programme2:

#include<stdio.h>
#include<conio.h>
void main()
{
int x=20;
clrscr();
printf("%f",x);
getch();
}

out put:

printf:floating format point not linked
abnormal programme termination.

My doubts: 1)the printf statement in both the programmes is same.But out put is different.why it happens? 2)is there any effect of the statement "float f=20.123" on the output. please clear my doubt. — Preceding unsigned comment added by Phanihup (talkcontribs) 00:31, 28 November 2012 (UTC)[reply]

Looks like a bad linker, to me, which correctly sees the "float" command as requiring that it link to the floating point module, but fails to see that the "%f" format also requires inclusion of the floating point module in the link list. (It is a bit odd to try to print an integer with a floating point format.) StuRat (talk) 00:39, 28 November 2012 (UTC)[reply]
%f in the printf format string says the corresponding argument is of type double, that is a Double-precision floating-point format number. In the first case you're passing it a float, but in the second you're passing an int. The two aren't compatible, so you get an error. A good compiler can detect this kind of thing: for example, gcc says "warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’" and clang says "warning: conversion specifies type 'double' but the argument has type 'int'" -- Finlay McWalterTalk 00:41, 28 November 2012 (UTC)[reply]
He's actually trying to print an integer as floating point, in both cases. In the first case, this produces an incorrect value, and in the second case, an error. StuRat (talk) 00:43, 28 November 2012 (UTC)[reply]
Quite right. It looks like this compiler (Phanihup: what compiler is it? Turbo C??) will omit the float part of the C library when it doesn't see a use of floating point in the source (and it's not smart enough to parse the format string). -- Finlay McWalterTalk 00:53, 28 November 2012 (UTC)[reply]
The C99 standard [1] says in 7.19.6.1.9 (PDF page 292): "If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined." Anything is consistent with "the behavior is undefined" so it's allowed to print some number in one case and an error message in another (although it's not the most helpful for debugging). By the way, the string "the behavior is undefined" occurs around 150 times in the standard. PrimeHunter (talk) 02:48, 28 November 2012 (UTC)[reply]
Even if "undefined", one would expect it to behave consistently. StuRat (talk) 03:13, 28 November 2012 (UTC)[reply]
Undefined is undefined. And actually removing the floating point library can be quite useful if one wants to produce a system routine where there is no floating point context. But yes the compiler should check printf formats as this is a very common type of error. Dmcq (talk) 15:29, 28 November 2012 (UTC)[reply]
Couple points:
  • The OP is evidently using a very old compiler. But the answer to the "floating point formats not linked" questin is straightforward: see the comp.lang.c FAQ list, question 14.13.
  • Passing a float value to the %f format in printf is actually not a mismatch. See the FAQ list again, question 12.9.
Steve Summit (talk) 03:20, 30 November 2012 (UTC)[reply]
Yes, passing a float value to the %f format is not a mismatch, as float is converted to double. However, Phanihup passes an int argument, not float. --CiaPan (talk) 05:54, 30 November 2012 (UTC)[reply]
The answers are:
  1. The float variable declaration tells the compiler a floating-point library is necessary, so it generates apropriate references. Then the linker attaches the library to your programme. That allows the printf() function to interpret %f format correctly, and that's why the first programme tries to print out some results, and the latter prints the error message.
  2. There's a big difference between how integer values and floating-point values are stored in memory – see Integer (computer science), Double-precision floating-point format.
    When you pass an int value to printf() the compiler does not check if int type fits %f requirements. Also printf, when scanning its printing format string, can't check wether you passed double or not. So it interprets appropriate place in memory, where it expects the double value to be printed out, and interprets your int value with Double-precision floating-point format. The result is zero, so the output 0.0000.
CiaPan (talk) 06:11, 30 November 2012 (UTC)[reply]

math word problem

[edit]

I've raked 2/3rd's of a yard full of leaves. If I rake 5200 more I'll be 8/9th's done. How many leaves were in the yard ? — Preceding unsigned comment added by 68.37.64.194 (talk) 02:33, 28 November 2012 (UTC)[reply]

Here goes.
  • 8 ninths minus two thirds=5200
  • 8 ninths minus two thirds=two ninths
  • 5200/2*9=23400
23400 leaves. Buggie111 (talk) 02:41, 28 November 2012 (UTC)[reply]
Looks good to me, although I'd encourage you to use a variable, such as X, to represent the total number of leaves:
 2x            8x
---- + 5200 = ----
 3             9
Also, once you've determined that X = 23400, you can plug it back in as a check:
2(23400)          8(23400)
-------- + 5200 = --------
    3                 9
          20800 = 20800
Both sides match, so it checks out. Always check your work. BTW, the Math Desk is the best place for Q's like this. StuRat (talk) 03:21, 28 November 2012 (UTC)[reply]

Browser fingerprint

[edit]

Besides private mode, disabling javascript and using a common browser, what else can you do to browser privately? PS: I don't want to use something like Tor. Comploose (talk) 15:15, 28 November 2012 (UTC)[reply]

Disable cookies (you can enable only the ones you truly care to have on most browsers) [private mode probably takes care of this], disable Flash (or at least Flash cookies) [no idea if private mode covers this], and avoid looking special according to any criteria at http://panopticlick.eff.org/. You could use a VPN as a proxy. ¦ Reisio (talk) 15:41, 28 November 2012 (UTC)[reply]
Yes, private mode + no javascript cover these points. According to panopticlick what makes me "special" is the user agent and HTTP_ACCEPT Headers. I know that I can change the first at least in Chrome, Firefox and IExplorer. But, I suppose that the most useful way of being private is to provide fake information in all topics that are being collected. Is that possible? This information has to be saved somewhere in the browser. Comploose (talk) 15:55, 28 November 2012 (UTC)[reply]
Fake isn't the goal - generic is. If you fake a combination of things that no one else is running, then you still have a unique identifier. It looks like the paper linked on the panopticlick site gives some common data at the end. Installing a browser version listed on the site and not changing many settings (other than private mode + no javascript) is probably a good start. 209.131.76.183 (talk) 16:02, 28 November 2012 (UTC)[reply]
Also, a plugin that switches between common user agents over time could be interesting. I wouldn't be surprised if something like that exists. 209.131.76.183 (talk) 16:03, 28 November 2012 (UTC)[reply]
Yes, I mean fake constantly, changing the parameters (fonts, cookies acceptance, HTTP_ACCEPT Headers, and so on) that I am supposed to have. That generates chaos. Otherwise, your browser would be the browser that discloses almost no information on the IP range 101.34.yy.xx. Disclosing less than others also makes you unique. Comploose (talk) 16:10, 28 November 2012 (UTC)[reply]
Alternate the use of several browsers, even the exotic ones, do just log-in and log-off before navigating to other pages (which is like telling you are there). And don't get paranoid about it, unless you have a reason for it. OsmanRF34 (talk) 19:25, 28 November 2012 (UTC)[reply]
The safest method I can think of is to use an O/S and browser that boots from a DVD, on a PC with no hard drive. Thus, it would have nowhere to store anything, no matter how hard it tried. Of course, the lack of cookies and such would also make browsing annoying, in that it wouldn't remember any logon IDs, preferences, etc. An advantage is that you would also be virtually virus-proof, and therefore wouldn't need a virus-scanner slowing down everything you do. StuRat (talk) 08:32, 29 November 2012 (UTC)[reply]
That's right regarding safety, but the question was about privacy online. In your scenario, I am afraid that you would "too unique", in the sense that not many others would have exactly the same configuration as you. In both cases, privacy and security, there's no need to get paranoid, the basics (safe passwords, no downloading and running any kind of stuff, updating your system) should be more than enough for most kind of users. OsmanRF34 (talk) 12:09, 29 November 2012 (UTC)[reply]

Unexpected JDWP error: 21

[edit]
Figured the problem out on my own, it was something unrelated to this one.
The following discussion has been closed. Please do not modify it.

I am trying to create a MIDlet in NetBeans 7.2. For some reason this line XYcoord temp = new XYcoord(0, 0); causes a java.lang.NullPointerException to occur. Debugging and hovering over the variable temp after trying to initialize it shows Unexpected JDWP error: 21. I have no idea how that happened.

Here's the XYcoord class, which is defined on an another file in the same package:

public class XYcoord
{
    int m_x;
    int m_y;
    public XYcoord(int x, int y)
    {
        m_x = x;
        m_y = y;
    }
    public int GiveX()
    {
        return m_x;
    }
    public int GiveY()
    {
        return m_y;
    }
}

Klilidiplomus+Talk 18:55, 28 November 2012 (UTC)[reply]

Resolved

Regulations on feature set in software comparison articles

[edit]

Comparison of BitTorrent clients (edit | talk | history | protect | delete | links | watch | logs | views)
There's an edit warring in the referenced article about whether to include a certain feature into the comparison. I advised them to seek consensus but am unsure of how to seek it in this case. The feature is of course covered in RS'es. And there doesn't appear to be any policies, guidelines or even prior discussions on picking a feature set for comparison. Are there any? — Vano 19:43, 28 November 2012 (UTC)[reply]

The relevant policy is WP:NPOV, but mostly, try to use good judgement and don't go along with people arguing against common sense. You can ask for outside comment at WP:Requests for comment. The reference desk is not actually appropriate for this type of question, which is one of WP:Dispute resolution. 67.119.3.105 (talk) 21:29, 28 November 2012 (UTC)[reply]
I thought it's appropriate to survey on existing practices which is what I did. You gave the answer on this, thanks. — Vano 22:01, 28 November 2012 (UTC)[reply]

What's the easiest way to create a local server with proxypass on Windows?

[edit]

I have a folder containing html content, and I'd like to serve it from http://somelocalhost. I also want to set up a ProxyPass so that I can define that somelocalhost/xyz could be pointed somewhere else.

On OS X I've always used Apache, but on Windows I'm having a lot of trouble setting it up. Is there something that's even easier that would work out-of-the-box on Windows? Or should I keep plugging away at making Apache work?

Thanks! — Mike 166.186.169.41 (talk) 21:44, 28 November 2012 (UTC)[reply]