OFF TOPIC ! Niggling point from a C programmer with a few gray hairs in his beard: #if 0 #endif is in fact the One True Way to comment out a block of code in ANSI C, since you can't use // and /* */ doesn't nest (i.e. you want to comment out a block of code that has a smaller block commented out already.) Yeah it's harder to see, but it always works and never leaves you scratching your head wondering why commenting out a code doesn't seem to have the exact intended effect. On the other side, I don't like seeing these things left in the code very long either. If I have #if 0's in my code, it usually means I haven't decided if the New Way is the Final Way, and it's usually better just to make the decision and let the source code control system keep the history. -- John. ON TOPIC ! --- Segher Boessenkool <segher@chello.nl> wrote:
There was some discussion on this list on probing compiler features before actually using them instead of making vague assumptions on what version supports which feature.
I still prefer just requiring gcc-3 (although it currently works "fine" with 2.95 as well) (except on some 64-bit targets).
Instead of using a vast amount of autoconf/automake magic, I wrote a small perl script that calls the compiler with simple code fragments and analyzes these afterwards using nm.
Good :) The autoevil suite is, well, evil ;)
This way it is also usable when cross compiling. Basically the patch removes types.h as it will be autogenerated plus the already known ANSI fixes (mostly applying a regexp to change comment style)
Please keep types.h intact, and have it include an auto-types.h or something like that. Much easier if you want to bypass the automatic stuff for whatever reason.
The configuration script conf.pl also checks for available data types and chooses the needed ones to set up the internal structures. gcc's TI mode is probed and, if available and needed, it is used.
Any comments? ;)
Walkthrough :) :
-CFLAGS = -Wall -W -std=gnu9x -g -O2 # -pg +CFLAGS = -Wall -std=gnu9x -g -O2 # -pg
Why remove -W ? It's soooo useful :)
+CC = gcc
I removed this for a reason ;) Just CC=gcc make if you need it...
+NM = nm -t bsd
Not all nm's are GNU nm. Different nm's outputs are similar enough to be parseable with a simple regexp.
-paflof.o paflof.s: paflof.c prim.code prep.h dict.xt +paflof.o paflof.s: paflof.c prim.code prep.h types.h dict.xt
Ah yes, I forgot. Thanks.
+$CC="gcc -std=gnu9x"; +$NM="nm";
Better just use sh's already-set variables for this.
+sub check_size +{ + my $what=shift; + my $attr=shift; + my $include=shift; + + # create .test.c file + open(F, ">.test.c");
Don't hide temporary files -- if you feel they clobber the source dir, create them somewhere else (like, /tmp).
+# Check for restrict keyword. +my $answer="no"; +print("\nChecking whether we can use the restrict keyword (C99)... "); +print(I "\n#define __RESTRICT__ ");
The C compiler already defines __STDC_VERSION__ to 199901L or greater if C99 features are supported.
-//#define DEBUG_STACKS -
Don't remove this, please ;) #undef it, if you want, but keep all compile-time flags at the top op file :)
#include <stdio.h> #include <stdlib.h> +#define __USE_XOPEN_EXTENDED #include <unistd.h> -#include <string.h> +#define __USE_MISC #include <sys/mman.h> +#include <string.h> #include <termios.h> +#define __USE_POSIX +#define __USE_POSIX199309 #include <signal.h> #include <fcntl.h>
This isn't exactly making stuff more portable, now is it?
struct interpreter { - cell *restrict data_stack; - cell *restrict return_stack; - cell *restrict dictionary; - char *restrict tib; - char *restrict pockets; + cell * __RESTRICT__ data_stack; + cell * __RESTRICT__ return_stack; + cell * __RESTRICT__ dictionary; + char * __RESTRICT__ tib; + char * __RESTRICT__ pockets; void *here; };
It would have been simpler had you done #define restrict if restrict isn't supported...
+#if 0 + free(i->data_stack); + free(i->return_stack); + free(i->dictionary); +#endif
#if 0 for commenting out code is evil, imho.
Well, I'll get to it.
Segher
- To unsubscribe: send mail to majordomo@freiburg.linux.de with 'unsubscribe openbios' in the body of the message http://www.freiburg.linux.de/OpenBIOS/ - free your system..
__________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com - To unsubscribe: send mail to majordomo@freiburg.linux.de with 'unsubscribe openbios' in the body of the message http://www.freiburg.linux.de/OpenBIOS/ - free your system..