Conversation
Notices
-
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 22:35:09 JST Pleroma-tan apparently all_digits is 96 bytes according to sizeof(all_digits), now i think i can do basic math, so i manually tried to count the byte size of the array, and i got 72 bytes
now either i'm bad at basic math or somethings going on-
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 22:35:17 JST Pleroma-tan @birdulon I thought digit was 9 bytes?sum of the members makes the size of the entire struct right? -
Embed this notice
Birdulon (birdulon@shpposter.club)'s status on Wednesday, 17-Apr-2024 22:35:18 JST Birdulon @kirby digit is 12 bytes, all_digits is 8 of that -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 22:37:10 JST Pleroma-tan @birdulon oh
-
Embed this notice
Birdulon (birdulon@shpposter.club)'s status on Wednesday, 17-Apr-2024 22:37:12 JST Birdulon @kirby it gets padded to a multiple of 4, at least in setups like this Pleroma-tan likes this.Pleroma-tan repeated this. -
Embed this notice
ロミンちゃん (romin@shitposter.world)'s status on Wednesday, 17-Apr-2024 22:37:27 JST ロミンちゃん @kirby structs and padding name a more iconic duo 翠星石 and Pleroma-tan like this. -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 22:39:16 JST Pleroma-tan @romin :akkoShrug: -
Embed this notice
"; DROP TABLE Users; (turboretard9000@bae.st)'s status on Wednesday, 17-Apr-2024 23:02:11 JST "; DROP TABLE Users; @birdulon @kirby yup, each instance of digits gets padded to 8 bytes, for a total of 12 for the struct, then I believe THAT gets padded to 16 Pleroma-tan likes this.Pleroma-tan repeated this. -
Embed this notice
"; DROP TABLE Users; (turboretard9000@bae.st)'s status on Wednesday, 17-Apr-2024 23:03:04 JST "; DROP TABLE Users; @birdulon @kirby ... I haven't built a compiler in forever though, don't quote me on this -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 23:07:35 JST Pleroma-tan @TURBORETARD9000 @birdulon how the hell do I predict the padding? Makes it a bit more difficult to calculate the amount of elements inside the array when this padding just comes in and fucks everything up -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 23:07:41 JST Pleroma-tan @TURBORETARD9000 @birdulon for the future I mean -
Embed this notice
Birdulon (birdulon@shpposter.club)'s status on Wednesday, 17-Apr-2024 23:16:23 JST Birdulon @kirby @TURBORETARD9000 there's compiler-specific ways to force it to not add padding, I don't think there's a general solution as it's so implementation-defined Pleroma-tan likes this.Pleroma-tan repeated this. -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 23:16:52 JST Pleroma-tan @birdulon @TURBORETARD9000 well thats great :fubukiD: -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 23:27:04 JST Pleroma-tan @romin @TURBORETARD9000 @birdulon no but it'd be nice to not have to define a macro just for the number of elements in an array and have to update it every time if I wanted to add a new addition of some sort -
Embed this notice
ロミンちゃん (romin@shitposter.world)'s status on Wednesday, 17-Apr-2024 23:27:07 JST ロミンちゃん @kirby @TURBORETARD9000 @birdulon
>how the hell do I predict the padding
why would you want to do that, are you writing driver/network code or somethingPleroma-tan likes this. -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 23:37:31 JST Pleroma-tan @TURBORETARD9000 @romin @birdulon you know what, no comment -
Embed this notice
"; DROP TABLE Users; (turboretard9000@bae.st)'s status on Wednesday, 17-Apr-2024 23:37:32 JST "; DROP TABLE Users; @kirby @romin @birdulon ... what are you doing? -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 23:38:54 JST Pleroma-tan @romin @TURBORETARD9000 @birdulon or maybe just ANY other higher level language for this task I just wanted to do for fun in c -
Embed this notice
ロミンちゃん (romin@shitposter.world)'s status on Wednesday, 17-Apr-2024 23:38:55 JST ロミンちゃん @kirby @TURBORETARD9000 @birdulon maybe r*st is a language more suited to your tastes, besides ARRAY_SIZE is a pretty standard macro Pleroma-tan likes this. -
Embed this notice
"; DROP TABLE Users; (turboretard9000@bae.st)'s status on Wednesday, 17-Apr-2024 23:39:02 JST "; DROP TABLE Users; @kirby @romin @birdulon like don't get me wrong I'm sure my repos are just as wacky
I'm just curiousPleroma-tan likes this. -
Embed this notice
"; DROP TABLE Users; (turboretard9000@bae.st)'s status on Wednesday, 17-Apr-2024 23:46:41 JST "; DROP TABLE Users; @birdulon @kirby if you aren't doing it like gcc you're wrong
OK but USUALLY
It'll start with the topmost element
That's always going to be aligned, so it never moves
The next element in the struct It'll grab, and align on the nearest aligned memory location for that elements size
So if element 1 is a byte, and element 2 is an int, element 0 will be at +0, element 1 will try to go to +1, but that isn't aligned. The nearest aligned location for an int is +4, so the compiler puts it there instead, and the previous three bytes are padding. If it were a short, it'd be put in +2, a long +8
The compiler then just keeps walking through the struct until it's done
The end padding tbh isn't too important unless you're worried about distances outside the struct, or arrays of structPleroma-tan likes this. -
Embed this notice
Birdulon (birdulon@shpposter.club)'s status on Wednesday, 17-Apr-2024 23:49:28 JST Birdulon @kirby @TURBORETARD9000 @romin it's not a true c project unless you're enjoying a few footguns Pleroma-tan likes this.Pleroma-tan repeated this. -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 23:49:50 JST Pleroma-tan @birdulon @TURBORETARD9000 @romin :aicool: -
Embed this notice
翠星石 (suiseiseki@freesoftwareextremist.com)'s status on Wednesday, 17-Apr-2024 23:51:22 JST 翠星石 @kirby >how the hell do I predict the padding? Makes it a bit more difficult to calculate the amount of elements inside the array
You don't need to care about the padding.
You just need to divide the total size of the array by the size of one element to get the number of elements;
int elements = sizeof(all_digits)/sizeof(all_digits[0]);Pleroma-tan likes this. -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 23:54:32 JST Pleroma-tan @Suiseiseki I thought the padding made a difference? -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Wednesday, 17-Apr-2024 23:55:47 JST Pleroma-tan @Suiseiseki oh wait, I was thinking of literally dividing by what I thought the size of an element would be
This is a much better workaround thanks -
Embed this notice
翠星石 (suiseiseki@freesoftwareextremist.com)'s status on Wednesday, 17-Apr-2024 23:59:30 JST 翠星石 @kirby For the purpose of calculating the number of elements with sizeof() it doesn't.
Padding isn't a problem in most cases in C, as no function cares about it - it's only if you do wrong things like try to dump structs directly to memory while making assumption about the byte layout (i.e. not telling gcc to pack the struct and not handling endianness) that you'll have issues. -
Embed this notice
"; DROP TABLE Users; (turboretard9000@bae.st)'s status on Thursday, 18-Apr-2024 00:02:01 JST "; DROP TABLE Users; @birdulon @kirby @romin That's what makes it exciting! Pleroma-tan likes this.
-
Embed this notice