Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Wed, 28 Aug 2002 20:45:40 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Wed, 28 Aug 2002 20:45:40 -0400 Received: from ip68-4-60-172.pv.oc.cox.net ([68.4.60.172]:1601 "EHLO siamese.dyndns.org") by vger.kernel.org with ESMTP id ; Wed, 28 Aug 2002 20:45:39 -0400 To: Jim Treadway cc: linux-kernel@vger.kernel.org, Subject: Re: [TRIVIAL] strlen("literal string") -> (sizeof("literal string")-1) References: From: junio@siamese.dyndns.org Date: 28 Aug 2002 17:49:51 -0700 In-Reply-To: Message-ID: <7vd6s2lc9c.fsf@siamese.dyndns.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1327 Lines: 37 >>>>> "JT" == Jim Treadway writes: JT> Would redefining strlen() as __strlen() and then using JT> #define strlen(x) (__builtin_constant_p(x) ? (sizeof(x) - 1) : __strlen(x)) JT> work in this situation? I thought about that before I posted the previous patch, but rejected it. If it worked in all situations then it would have been great, but it fails in at least one way [*1*], so you cannot generally define the above in a header file which everybody includes. Instead, you end up examining each use of strlen() and make the above "#define" only where it does not break; it is not worth the aggravation. Something named "strlen" must work in all situations, and "in this situation" is not good enough. Otherwise it would confuse/surprise people. [Footnotes] *1* It fails on the following: #define FOOBARBAZ &("foobarbaz"[0]) void main(void) { int sz; if (__builtin_constant_p(FOOBARBAZ)) { sz = sizeof(FOOBARBAZ) - 1; printf("sizeof(FOOBARBAZ) -1 = %d\n", sz); } printf("strlen(FOOBARBAZ) = %d\n", strlen(FOOBARBAZ)); exit(0); } - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/