Skip to main content
18 events
when toggle format what by license comment
Nov 12, 2019 at 0:09 vote accept S.S. Anne
Nov 7, 2019 at 21:25 comment added S.S. Anne @chux-ReinstateMonica Ah, figured it out. I forgot to add cptr-str in at the end.
Nov 7, 2019 at 21:08 comment added chux @JL2210 Different aliments. Print their pointer values.
Nov 7, 2019 at 20:26 comment added S.S. Anne @chux-ReinstateMonica For some reason, the results differ between char s[]="It works!"; strlen(s); and char *s="It works!"; strlen(s);. Do you have any idea why?
Nov 7, 2019 at 19:23 comment added chux @JL2210 Perhaps form a helper function/macro to assess alignment. I'd expect your initial approach to be fine for 99+% of systems.
Nov 7, 2019 at 17:33 comment added S.S. Anne I feared this when I wrote the code. I'll keep working on it.
Nov 7, 2019 at 11:52 history edited chux CC BY-SA 4.0
added 4 characters in body
Nov 7, 2019 at 11:45 history edited chux CC BY-SA 4.0
deleted 8 characters in body
Nov 7, 2019 at 11:36 history edited chux CC BY-SA 4.0
deleted 8 characters in body
Nov 7, 2019 at 11:30 history edited chux CC BY-SA 4.0
deleted 247 characters in body
Nov 7, 2019 at 11:24 history edited chux CC BY-SA 4.0
deleted 247 characters in body
Nov 7, 2019 at 11:15 comment added chux @TobySpeight CHAR_BIT == 12, sizeof (uint32_t) == 3 is not possible: uint32_t cannot have padding. sizeof (uint32_t) must be a power of two. With CHAR_BIT == 12, The optional type uint32_t cannot be defined. Yet the larger issue is that an aligned pointer, when converted to an integer, is not specified to a value with lower bits of 0. That is just common implementation. Exotic example per OP's "possibly some uncommon ones?": the least significant bit of the (uintptr_t)cptr could be the parity of the address - not useful for determining alignment.
Nov 7, 2019 at 9:25 comment added Toby Speight That's a really opaque way to do alignment; I don't like the assumption that sizeof (uint32_t) must be a power of two. One can imagine an (admittedly not "common") implementation with CHAR_BIT == 12, and sizeof (uint32_t) == 3. C++ has std::align(); it might be worth creating a similar function here.
Nov 6, 2019 at 21:57 history edited chux CC BY-SA 4.0
added 21 characters in body
Nov 6, 2019 at 21:55 comment added chux @JL2210 I see the single &. (Amended answer as part of the answer did act like && - that part was in error) The cast to uintptr_t does not yield a specified value in which bit-wise adding with (sizeof(uint32_t)-1)) results is a specified alignment test. AFAIK, this is no specified alignment test.
Nov 6, 2019 at 21:27 comment added S.S. Anne I used &, not &&. The cast to uintptr_t was intentional.
Nov 6, 2019 at 20:34 history edited chux CC BY-SA 4.0
added 306 characters in body
Nov 6, 2019 at 19:54 history answered chux CC BY-SA 4.0