Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site hp-pcd.UUCP Path: utzoo!linus!decvax!harpo!floyd!clyde!ihnp4!zehntel!hplabs!hp-pcd!hp-dcde!jack From: jack@hp-dcde.UUCP Newsgroups: net.lang.c Subject: compile-time function - (nf) Message-ID: <2079@hp-pcd.UUCP> Date: Fri, 14-Oct-83 03:29:54 EDT Article-I.D.: hp-pcd.2079 Posted: Fri Oct 14 03:29:54 1983 Date-Received: Sun, 16-Oct-83 08:41:36 EDT Sender: notes_gateway@hp-pcd.UUCP Organization: Hewlett-Packard, Fort Collins, CO Lines: 30 #N:hp-dcde:20000001:000:517 hp-dcde!jack Oct 12 19:00:00 1983 I want to define a compile-time function. For example: #define LOG2(n) \ #if n==1 \ 0 \ #endif \ #if n==2 \ 1 \ #endif \ #if n==4 \ 2 \ #endif \ ... and so on ... i = LOG2(4); Which I want to produce i = 2. However, it seems that the whole macro definition gets put together on a single line before the preprocessor checks for #if's, so the #if's aren't recognized. How can I (for the general case, not just LOG2) do something like this? -Jack Applin Hewlett-Packard (hplabs!hp-dcd!jack)