Re: Compute buffer size at compile-time
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Apr 2006 10:53:05 -0400
Ico wrote:
Spoon <none> wrote:
Hello,
Consider:
#define BUFFER_SIZE 1234 /* or some other value */
uint8_t buffer[BUFFER_SIZE];
int do_stuff(uint8_t *buf);
where do_stuff() does something with each octet in the buffer.
Assume I've come up with do_stuff_2() similar to do_stuff() but
that works with 16 octets at a time.
I need to compute N at compile time
such that N >= 1234 && N % 16 == 0
#define N (BS / 16) * 16 + 16 ?
Be careful of those boundary cases. If BS is divisible
by 16, the above formula adds an extra 16 instead of just
leaving it alone.
#define N ((BS + 15) & ~15)
More generally,
#define ROUNDUP(min,chunk) \
(((min) + (chunk) - 1) / (chunk) * (chunk))
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxx
.
- References:
- Compute buffer size at compile-time
- From: Spoon
- Re: Compute buffer size at compile-time
- From: Ico
- Compute buffer size at compile-time
- Prev by Date: Re: Function Signatures In time.h
- Next by Date: Re: Compute buffer size at compile-time
- Previous by thread: Re: Compute buffer size at compile-time
- Next by thread: Re: Compute buffer size at compile-time
- Index(es):
Relevant Pages
|