« first day (2790 days earlier)      last day (1062 days later) » 

13:27
@stanle it's not empty... :P Just becoming stale from time to time a bit...
 
3 hours later…
16:54
i'm still dumbfounded about pointer alignment @Kamiccolo lol
it's tricky indeed :}
typedef struct {
    char a;
    short b;
    int c;
} my_struct;

my_struct s;
char buff[50];
memcpy(buff, &s, sizeof(s));
anything wrong with that yet?
(lets pretend my_struct is packed since I can't edit it anymore)
uh oh, go ahead millennium, ruin my day :'D
@milleniumbug @Kamiccolo I'm assuming something there has to be UB?
the cast maybe?
17:19
i'm really not trying to be annoying here. hoping yall can bear with me.

my thought is, alignment isn't needed for char *, right. So if I store my data in char buffer, then do someting like `my_struct *ptr = (my_struct *)buff`, then I can use direct access with the pointer to set the value in the buffer, e.g. `ptr->b = 1000;`
17:36
sorry, currently stuck with some work to do first
18:03
@Kcvin unaligned access
which part?
*p = 1337;
the entire "attempt to create an unaligned pointer" part is also sus af
but not sure if this alone constitutes UB
also note that __attribute((packed)), by itself, is not in the C standard, so we're talking about compiler extensions now
gcc, with this extension, makes sure that the direct access to the fields (as in, whatever you did with s.b = 2;) is safe on all CPUs, even if this involves reading twice, bitshifting, or what not, in order to not make an unaligned read
by accessing it through a pointer, the compiler no longer makes sure of that
@milleniumbug so how can i pull a short out of a char buffer? and how would I set it, the right way?
18:49
memcpy, I guess?
char whatever[50]; // let's assume it's filled with the content
short value;
memcpy(&value, whatever + offset, sizeof value);
@milleniumbug so we'd be looking at something more along the lines of this as being correct?: ideone.com/fwU1Ke
I think that will be perfect in terms of C standard compliance (of course aside from using the __attribute__((packed)) part in the first place). It's also unwieldy
I just updated the code, see the bottom of it.
casting buff to pointer of my_struct, then accessing it, that's bad i take it?
because if its packed, b would be unaligned, so accessing it would be unaligned access
how *ptr wouldn't be unaligned... so maybe that's not true?
20:05
but* (not how)

« first day (2790 days earlier)      last day (1062 days later) »