Path: ...!news.nobody.at!news.swapon.de!news.in-chemnitz.de!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail From: Alan Mackenzie Newsgroups: comp.lang.c Subject: Is it possible to generate a compile time error from an inline function? Date: Sat, 13 Jul 2024 13:04:04 -0000 (UTC) Organization: muc.de e.V. Message-ID: Injection-Date: Sat, 13 Jul 2024 13:04:04 -0000 (UTC) Injection-Info: news.muc.de; posting-host="news.muc.de:2001:608:1000::2"; logging-data="21179"; mail-complaints-to="news-admin@muc.de" User-Agent: tin/2.6.3-20231224 ("Banff") (FreeBSD/14.0-RELEASE-p5 (amd64)) Bytes: 1809 Lines: 33 Hello, comp.lang.c. What I want to do is check the validity of (constant) arguments to an inline function, and output a compiler error if they are invalid. In particular, I have: u32 __always_inline ACM_BITFIELD (u8 a[], int offset, int length) , which is to extract a bitfield of LENGTH bits, starting at bit number OFFSET in the array of bytes A. OFFSET and LENGTH will be known at compile time. For the sake of run time efficiency, I wish to impose the restrictions that either (i) the bitfield will be contained entirely within a byte; or (ii) the bitfield will be a number of consecutive whole bytes (maximum 32 bits). So, for example, if the code called foo = ACM_BITFIELD (bar, 14, 4); , I would like to output the compiler message "Invalid arguments 14, 4, to ACM_BITFIELD", since this bitfield straddles two bytes. Is there any way I can do this in C? (Before anybody asks, yes I have looked at doing it with macros, but that seems impractical, if it's even possible.) Thanks! -- Alan Mackenzie (Nuremberg, Germany).