Date: Mon, 3 Apr 2000 18:34:18 +0200 From: Samuel Tardieu <sam@inf.enst.fr> To: John Polstra <jdp@polstra.com> Cc: bright@wintelcom.net, current@freebsd.org Subject: Re: MLEN and crashes Message-ID: <2000-04-03-18-34-19%2Btrackit%2Bsam@inf.enst.fr> In-Reply-To: <200004031622.JAA19715@vashon.polstra.com>; from jdp@polstra.com on Mon, Apr 03, 2000 at 09:22:09AM -0700 References: <Pine.BSF.4.21.0004022118510.1442-100000@alphplex.bde.org> <20000403084330.6A6DC483D@hcswork.hcs.de> <20000403023858.F21029@fw.wintelcom.net> <200004031622.JAA19715@vashon.polstra.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 3/04, John Polstra wrote: | I doubt if it's possible to implement that at compile time. Remember, | the preprocessor doesn't understand "sizeof". It doesn't recognize | keywords in expressions at all. Then don't use the preprocessor alone and use both the preprocessor and the compiler. I suppose something like this will work: struct foobar { ...; } #ifdef CHECK_STRUCT_SIZE #define MAX_FOOBAR_SIZE 8 static char dummy_foobar [MAX_FOOBAR_SIZE-sizeof(struct foobar)]; #undef MAX_FOOBAR_SIZE #endif If sizeof(struct foobar) is more than MAX_FOOBAR_SIZE, then the compiler will try to create an array with a negative size, which will not compile. Embed this in a macro and you're done: #ifdef CHECK_STRUCT_SIZE #define CSS(S,T,U) static char dummy_##T [U-sizeof(S)]; #else #define CSS(S,T,U) #endif Then use: CSS(struct foobar,foobar,8) Sam To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2000-04-03-18-34-19%2Btrackit%2Bsam>