Mihail
If it divides by 400 it divides by 100
olli
If it divides by 400 it divides by 100
if the year number is divisble by 400 or by 4 but not 100 it is a leap year
Mihail
if the year number is divisble by 400 or by 4 but not 100 it is a leap year
It can't be divisible by 400 and not by 100 tho
olli
It can't be divisible by 400 and not by 100 tho
of course not. but if it is divisible by 100 but not by 400 is no leap year
Ariana
xor edx edx mov eax DWORD year mov ebx 4 idiv ebx cmp edx 0 jne [eip+2] ret 0 mov eax DWORD year mov ebx 100 idiv ebx cmp edx 0 jne [eip+2] ret 1 mov eax DWORD year mov ebx 400 idiv ebx cmp edx 0 jne [eip+2] ret 0 ret 1
Ak47
What's the point of the 100 division?
We make easy calculation as possible
Mihail
of course not. but if it is divisible by 100 but not by 400 is no leap year
Then just dividing by 400 or 4 will ignore that situation
Ariana
BinaryByter
Thats not tow leap year work, is it?
BinaryByter
if (year % 4 == 0)return true;
olli
just if(yr%4)return 0; if(!yr%400)return 1; if(yr%100)return 1; return 0;
returns the same on 2000 and 1900 - so not correct
Mihail
Because if divisible by 400 it's divisivle by 4 too
olli
if (year % 4 == 0)return true;
returns true on 1900 which is not a leap year
olli
It returns 1 for 2000 since !2000%400=1
yes but the same for 1900 2000 is a leap year, 1900 is not. so the result should differ
Mihail
returns true on 1900 which is not a leap year
How would your extra 100 and 400 divisions help with that?
Ariana
whoops swopped the rets
Ak47
After every 4 year 1 leap year added
Ak47
And after 400 year 1 leap year added
Ak47
Every century is not a leap year
Ak47
A century divided by 400 is an leap year
BinaryByter
Oh thats how they work
BinaryByter
Wayy too sophisticated
Ak47
And non century year divided by 4 is leap
Ak47
So we use 400 & 4 to check leap year
olli
bool isLeapYear(int year) { if (year % 400 == 0) return true: if (year % 100 == 0) return false; if (year % 4 == 0) return true: return false; } — or— bool isLeapYear(int y) { return y % 100 == 0 ? y % 400 == 0 : y % 4 == 0; }
Ak47
And use 100 too check first it if it is a century year we divide it by 400 otherwise by 4
Ak47
Mihail
You just don't indent it, so it's unreadable
Mihail
Smart
Mihail
Ak47
Well it is solved🤣🤣🤣
Azrul
hyeee
Anonymous
Welcome me
Anonymous
@ollie I have a short question
BinaryByter
#meta
Anonymous
Anonymous
@ollirz
Anonymous
@ollirz btw
Thanks 😄
olli
If there was ||, not &&; would right side be evaluated?
yes exactly, the expression on the right side will be evaluated if the left side is false, which holds for this case Using ||, if the left side is true however, the right side will not be evaluate because true or anything is always true To cite the standard [expr.log.or] The || operator groups left-to-right. The operands are both contextually converted to bool. The result is true if either of its operands is true, and false otherwise. Unlike |, || guarantees left-to-right evaluation; moreover, the second operand is not evaluated if the first operand evaluates to true. The result is a bool. If the second expression is evaluated, every value computation and side effect associated with the first expression is sequenced before every value computation and side effect associated with the second expression.
olli
Thank you so much !
You're welcome :)
klimi
Morning
Ludovic 'Archivist'
Structs are just legacies from C
In c++ a struct is a class with default accessibility set to public @Kurimi
Tolulope
Thanks
Stefan
in structs by default members are public
do you know why structs are by default public? they have to align with pod from c
Stefan
in c# they are not public by default
Stefan
http://wiki.c2.com/?PlainOldData
Joe
Hi guys quick question: how would you go about making a socket connection between a windows (server) and linux (client) device? is it difficult?
Ludovic 'Archivist'
do you know why structs are by default public? they have to align with pod from c
That is not true as struct in C++ can hold a virtual table if you declare virtual functions inside
Stefan
remember the days of typedef struct foo_t { ... } foo_t;?
Ludovic 'Archivist'
this is just some late additions, c structs can never do that
Never talked of C, late additions from 1987
Ludovic 'Archivist'
this is just some late additions, c structs can never do that
Also, nothing prevent you from including function pointers in a C struct
Stefan
but without c struct there wouldn't be c++ struct either
Ludovic 'Archivist'
Making it effectively a vtable
Stefan
Making it effectively a vtable
which is an egregious form of vtable yes
Ludovic 'Archivist'
Also, composition tricks C into having inheritance in structs
Stefan
Ludovic 'Archivist'
that's gnu extension far as i know
No, just putting a field at the beginning for your struct declaration that is the generalization
Ludovic 'Archivist'
This is pure ANSI C
Stefan
No, just putting a field at the beginning for your struct declaration that is the generalization
i tried to do this kind of pseudo oop with macro until i realized the vtable is always packed in the center
Ludovic 'Archivist'
ANSI C cannot reorder fields, your compiler is broken