0

I know what retyping does. But what I would like to know is how does it do that.

So I have this code

double n = 312.658328;
int x = (int)n;

if I statically assign the value like I did in this example, I can imagine that it could be compiler which does the conversion by cutting the number, but what if this happens runtime, with runtime calculated value.

Does it just resize the memory allocated to the variable, so that remaining bytes that don't fit into int are ignored and later rewritten by other data? Or does it produce some conversion code which recalculated the larger data which use floating point into smaller data with no floating point?

Anirudh Ramanathan
  • 46,179
  • 22
  • 132
  • 191
Petr
  • 13,747
  • 20
  • 89
  • 144
  • 3
    First, look up the name of the thing you have a question about. Some documentation about what it precisely does will likely be nearby. `(int)n` is a C *cast* and it causes a *conversion* to happen. – Pascal Cuoq Nov 22 '13 at 08:27
  • He has the wrong term. Petr, you need to look up the term "cast". – Ira Baxter Nov 22 '13 at 08:28
  • You can use safe cast : int x = static_cast n; – Md. Al-Amin Nov 22 '13 at 08:28
  • 3
    I've not been on SO for long, but sometimes the negativity of people surprises me. This sounds like a valid question to me. Why all the downvotes? @Petr, the actual name is "casting". – CompuChip Nov 22 '13 at 08:28
  • ok, this may be duplicate... I am just wondering why same questions one receive -3 votes and the other one, even if it's the same, +17 :-) – Petr Nov 22 '13 at 08:29
  • 3
    @Petr I think it is because people perceive getting the term wrong as not having made an effort to understand :) – Anirudh Ramanathan Nov 22 '13 at 08:29
  • 2
    All: if a person doesn't have the right term, its pretty hard to look it up. You can't blame him for that. Petr: +1 for having the nerve to ask a naive question. – Ira Baxter Nov 22 '13 at 08:33
  • @Petr I'd suggest that the question's title not be changed. A duplicate with nearly the same title isn't very helpful to future visitors. – Anirudh Ramanathan Nov 22 '13 at 08:34
  • 4
    @CompuChip - Why all the downvotes? Simple really, a downvote is in order if `"This question does not show any research effort; it is unclear or not useful"` - that's what it says when you hover over the down-vote button. It's not a social website or one that cares about people's feelings - it's a technical question and answer board. Letting poor quality content survive merely dilutes the good stuff and reinforces the impression that said content will be accepted. It's a mistake to take downvotes personally. They're a chance to improve. – enhzflep Nov 22 '13 at 08:36
  • 3
    @ehnzflep, nothing personal. But I agree with Ira that if you search for the wrong words it can be hard to find an answer, sometimes all you need is a pointer "it's called _X_, try searching for that". Also, I see a lot of basic questions like "I just learned how to spell C++, now how do I do ...". This question is really asking for a deeper technical understanding that most people won't bother to go into, therefore I would classify it as neither unclear, nor not useful. Just my 2 cents - it's been established as a duplicate, with a link to a pretty extensive thread which hopefully covers all. – CompuChip Nov 22 '13 at 08:48

0 Answers0