« first day (1751 days earlier)      last day (3284 days later) » 

11:01 PM
But it's trading one large convenience on my end, for many inconveniences on the user's end :(
@OMGtechy It's not performance critical, so I have to go with the "most correct" solution
template <class A, class B> void LameCopy(A& dst, B& src) {
	char* D = reinterpret_cast<char*>(&dst);
	char* S = reinterpret_cast<char*>(&src);
	int L = (sizeof(src) < sizeof(dst)) ? sizeof(src) : sizeof(dst);
	while (L--) D[L] = S[L];
	return;
}
 
why can't you just use memcpy again?
 
I don't know, I probably can, but it takes void* not char*
 
yeah that's the point
where you can void* you can basically have T*
it's the "whatever" pointer
front the days of C where we didn't have templates
 
I know that char* and unsigned char* are the magic ways to be "allowed" to break strict aliasing
I'd have to do a research report to find out if void is lol
 
11:13 PM
21
Q: When to use a void pointer?

Mac13I understand the use of void pointer for malloc implementation. void* malloc ( size_t size ); Can anyone suggest other reasons or provide some scenarios where it is useful in practice. Thanks

@MickLH
@TheMuffinCoder it is the sacrifice we make
 
@OMGtechy is this the only reason we go to college then?
to find people who do? :P
 
ahahah
I don't know what it's like over there, but over here it's mainly to get drunk and have a piece of paper that says "I know stuff!"
I'd imagine the same
 
@OMGtechy xD same here basically
 
I never went though
 
lol but i do think college will teach a lot
 
11:15 PM
I assume when you say college you mean what I call university btw
and I should hope so
 
sure! :P
hoping to get to go somewhere good for really cheap
gotta take all the ap's
 
I just realised it's been so long since I wrote a sorting function I've literally forgotten how to do it
after a week at work my mind just doesn't want to wake up
soooo I'll just use std::sort
 
am surprised Brendan Eich answered this himself
 
niceee
 
11:28 PM
@OMGtechy so........ gcc provides __attribute__((__may_alias__)) lol
to basically do -fno-strict-aliasing on only one variable
 
do you care about anything other than gcc?
 
Theoretically I don't have to ;)
 
umm ok
 
11:41 PM
@MickLH wellllll I've just gone and done some UB of my own; the union thing
for now I cba and know it'll work 99% of the time, and there's a TODO to do it properly
        union
        {
            byte bytes[4];
            uint32_t count;
        } toWrite;

        // strictly speaking this is UB, but it'll do for now
        // whilst most use unions to reinterpret bytes, it's UB!
        // with that said, most implementations do what's expected
        // TODO - correct this
        toWrite.count = static_cast<uint32_t>(lookup.size());

        target.write(toWrite.bytes, 4);
0
Q: Error. Fix it now or else the world will end

Matthew Sheeler bubster20<div id="y"> <button onClick="p3()"> 3 Players </button> </div> <div id="x"> </div> <button id="bla"></button><button class="a" id="whi1"></button><button class="a" id="whi2"></button><button class="a" whi="whi3"></button> <script> var x = document.getElementById('x'); ...

 
uint32_t count = lookup.size();
target.write((char*)&count, 4);
I think that's not actually UB
 
ah fair point
well it's more defined anyway
I'll do that, ty
 
I would also use sizeof(toWrite) instead of 4.
 
even better
 
int main() {
    if (sizeof(int) != 4) printf("Warning: Lol ur so screwd mate. GL!\n");
    // program here
}
 
11:48 PM
uint32_t count = static_cast<uint32_t>(lookup.size());
target.write(reinterpret_cast<char*>(&count), sizeof(count));
@MickLH well I'm using uint32_t for that exact reason
 
That makes the 4 completely fine
I believe the purpose of stdint.h is to have these fixed size integers consistently
 
yeah but using sizeof expresses it more clearly and means I don't break things if I change it to a 64 bit int later
@MickLH yes it is
 
lol... except your file (network?) format
 
it's only a toy :P
 
Up to the point you decide you want to make toWrite a smaller object to save space/bandwidth/whatever, and have to find all instances of 4 in your code.
 
11:50 PM
^
 
Actually, nvm, that would not help much in this case.
 
You still have to find all instances of uint32_t in this scenario
 
I don't take endianness into account yet
@MickLH not if I type using data_t = uint32_t
or something like that
 
That's that scenario ;)
 
well I only have it in one place at the moment so shh :P
if I have more dictionary values than a uint32_t can hold then wth man
 
11:51 PM
Getting the right answer means correcting your wrong answer before anyone sees ;)
 
there's a check in there that's basically "lol no" if you need more than that
 
lol I am fairly sure that using memcpy the way we talked about earlier is well defined but I can't prove it
 
At work we have this stuff that formally proves that some software / hardware has no bugs, my reaction was like WTF
I didn't think that was possible
but it turns out you can
 
It seems to come down to the implementation of memcpy itself, as long as memcpy is implemented with char* (or unsigned char*) then I believe it's defined.
 
11:54 PM
just look at the spec
 
Pip
@SpartanDonut nice
 
@SpartanDonut hell yeah
 
lol considering a few screenshots of what people have been banned for, like half of league's population is going to disappear
and the system jumps straight to a 2 week ban for the first offense
 
Probably for the best
 
11:56 PM
@SpartanDonut lol "Dear Spartan, We got that fucking fucker. You're awesome bro. --Rito"
 
edit that to say Rito and it's gold ;)
 
Lol am I being duped, I am scared because I don't know who Rito is
 
@MickLH the joke is "Rito pls" every time someone wants something of them
usually its some stupid bug
 
Pip
Volvo pls
 
11:58 PM
nice
 
omg last 2 seconds intense
 
Pip
lol
 
[checks everyone for suspensions]
 
wait I go for a few seconds come back and there's removed everywhere
what did I miss
 
Mick said "Rito"
 
11:59 PM
hahaha that looks worse than it is from outside
 
umm, ok
 

« first day (1751 days earlier)      last day (3284 days later) »