Author

Topic: What happen write number like this at code? (Read 204 times)

full member
Activity: 198
Merit: 130
Some random software engineer
April 06, 2018, 12:02:52 AM
#8
So if type like,

nSubsidy >>= (nHeight / 5,112,000);

then 5,112,000 become to what number for computer?  

I suggest you take a look at the Comma operator page on Wikipedia, as it will explain it better than me:

In the C and C++ programming languages, the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type).

Your code will then only do the following:

Code:
nSubsidy >>= 000;

(The first & the 2nd statement are discarded)

You can try it out by yourself:

Code:
$ cat a.c && gcc -Wall -o a a.c && ./a
#include

int main() {
    int a, b;

    a = (1, 2, 3);
    printf("a == %d\n", a);
}
a.c: In function ‘main’:
a.c:6:11: warning: left-hand operand of comma expression has no effect [-Wunused-value]
     a = (1, 2, 3);
           ^
a.c:6:14: warning: left-hand operand of comma expression has no effect [-Wunused-value]
     a = (1, 2, 3);
              ^
a == 3

A valid usage:

Code:
$ cat a.c && gcc -Wall -o a a.c && ./a
#include

int main() {
    int a, b;

    b = 1;
    a = (a = b+1, a--, a+1);
    printf("a == %d\n", a);
}
a == 2

The code is executed the following: b = 1; a = b+1 (a will be == 2); a-- (a will be == 1); a+1 will return 2 then this value will be assigned to a. a results as 2.


As you'll see on the wikipedia page, the comma operator has multiple usages.
HCP
legendary
Activity: 2086
Merit: 4361
Depends on the programming/scripting language being used and the compiler...

In all likelihood, the statement: nSubsidy >>= (nHeight / 5,112,000);
Is being interpreted as: nSubsidy >>= ( (nHeight/5), 112, 000);

Ie. the "number" 5,112,000 is effectively being interpreted as three separate numbers... (5, 112 and 000)

Whether or not that is actually a "valid" statement is dependent on the language.

If it is C\C++, then I suspect that it will attempt to bit shift the value of nSubsidy to the right by "0" bits... the end result being that the value of nSubsidy will NOT change at all. But I haven't tested that.
staff
Activity: 3458
Merit: 6793
Just writing some code
So if type like,

nSubsidy >>= (nHeight / 5,112,000);

then 5,112,000 become to what number for computer?  
It doesn't become any number. Code is just text to a computer and is completely meaningless until it is compiled. That number will never have meaning to a computer because it will never be compiled into machine code that has meaning to a computer.
jr. member
Activity: 413
Merit: 5
As what number program recognize that , (comma) number?
May I know what are you clearly speaking about? If you type your question clearly I will edit this and try to give out the answer!  Huh
So if type like,

nSubsidy >>= (nHeight / 5,112,000);

then 5,112,000 become to what number for computer?  
legendary
Activity: 1584
Merit: 1280
Heisenberg Design Services
So if type like,
nSubsidy >>= (nHeight / 5,112,000);
then 5,112,000 become to what number for computer?  
As other members has given out some exact answers to your question, by the way what do you mean by numbers? Do you mean binary numbers Huh Comma operators can give out a varied results based on its usage in the code. At some times, it may even change the meaning of the code.

For instance consider a simple line of code where

a= b, c here in this the compiler reads them as a=b and a=c which will be similar to your case

if you use 5,112,000 instead of 5112000 as it meant to be, the compiler would end up with compiling 5 separately and 112 separately and 000 separately which would change your code. Hence don't try to use comma unless you are clear with them of where to use them.

And for your question about the number which computer reads, if you compile the 5112000, this would be converted to binary which is 10011100000000011000000 and would be given to the computer which reads them and replies.
jr. member
Activity: 413
Merit: 5
Compilers don't understand human comma separating for numbers. This code should fail to compile.
compiled was done with just warning sign. Not failed.

As what number program recognize that , (comma) number?
staff
Activity: 3458
Merit: 6793
Just writing some code
Compilers don't understand human comma separating for numbers. This code should fail to compile.
jr. member
Activity: 413
Merit: 5
So it should be,
nSubsidy >>= (nHeight / 5112000);


then what happen write like
nSubsidy >>= (nHeight / 5,112,000);

?

Jump to: