From owner-freebsd-current Mon Apr 3 9:36: 9 2000 Delivered-To: freebsd-current@freebsd.org Received: from ada.eu.org (marvin.enst.fr [137.194.161.2]) by hub.freebsd.org (Postfix) with ESMTP id 4AF0C37BB7B for ; Mon, 3 Apr 2000 09:35:53 -0700 (PDT) (envelope-from sam@inf.enst.fr) Received: from antinea.enst.fr (antinea.enst.fr [137.194.160.145]) by ada.eu.org (Postfix) with ESMTP id 1D3B719078; Mon, 3 Apr 2000 18:34:23 +0200 (CEST) Received: by antinea.enst.fr (Postfix, from userid 1000) id 78F43412; Mon, 3 Apr 2000 18:34:19 +0200 (CEST) Date: Mon, 3 Apr 2000 18:34:18 +0200 To: John Polstra Cc: bright@wintelcom.net, current@freebsd.org Subject: Re: MLEN and crashes References: <20000403084330.6A6DC483D@hcswork.hcs.de> <20000403023858.F21029@fw.wintelcom.net> <200004031622.JAA19715@vashon.polstra.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <200004031622.JAA19715@vashon.polstra.com>; from jdp@polstra.com on Mon, Apr 03, 2000 at 09:22:09AM -0700 From: Samuel Tardieu Organization: Ecole Nationale Superieure des Telecommunications Reply-To: Samuel Tardieu Content-Transfer-Encoding: 8bit X-WWW: http://www.inf.enst.fr/~tardieu/ X-Mail-Processing: Sam's procmail tools X-ICQ: 21547599 Message-Id: <2000-04-03-18-34-19+trackit+sam@inf.enst.fr> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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