Re: [PATCH 01/10] ivec: introduce the C side of ivec
- From
Jeff King <peff@peff.net>
- Date
- Jan 19, 2026, 20:40 UTC
- Message-ID
- <20260119204010.GA3148606@coredump.intra.peff.net>
- In-Reply-To
- <CAH=ZcbCXAB3vzRbyHkunQh09njyLk4WXvfLVxynXaswEkBv+DA@mail.gmail.com>
On Mon, Jan 19, 2026 at 01:21:04PM -0700, Ezekiel Newren wrote:
> Ok..., is there a way to pad a field to the largest size needed so > that this also works on the harvard architecture? If C isn't even self > consistent then how are these structs going to be passed between C and > Rust (which is THE point of ivec)?
If you make a union of the pointers, it will require the largest size and the strictest alignment requirement. So:
struct foo {
union {
void *v;
uint8_t *u8;
} ptr;
size_t len;
};would be a single struct you could use to store a void pointer _or_ a u8 pointer. The one thing you shouldn't do there, though, is assign via one union member and read from the other. So I don't know if that helps you or not (I confess I have not followed this rust discussion at all, and know nothing about rust/c ABI compatibility, and just got roped in on C esoterica).
> Or do we just tell the arcane Harvard architecture "too bad" Git won't > run on it anymore?
Minor nit: the Harvard architecture is one where function pointers are not the same as data pointers. An int/char distinction can happen even on more common (von Neumann) machines.
But I think we can rephrase your question as: are there real-world machines we care about that will have different pointer sizes, or can we ignore this issue for practical purposes?
I don't know the answer. I suspect it probably is OK for Git not to run on the machines mentioned in that C faq. But:
1. Sometimes there are subtle implications of undefined behavior that
may cause a compiler (even for a sensible machine) to do unexpected
things. I don't know offhand if that is the case here. 2. There are some modern platforms in which pointers are a bit more
opaque than just numeric addresses. For example, we've had a few
patches dealing with questionable pointer usage to make things work
on CHERI Arm systems. I'm not sure if any of that would matter
here, though (IIRC, it was mostly that pointers were unexpectedly
large and had matching alignment requirements, but all of them
equally so).-Peff