5 ms·
All the Pascal fanboys did this (and worse) before they gave in and finally converted :) #define begin { #define end }
by doctorwho 12y ago
All the Pascal fanboys did this (and worse) before they gave in and finally converted :)
#define begin {
#define end }
- pjmlp 12y agoBy worse do you mean? #define new(x) (malloc(sizeof(x))) #define dispose(x) { if((x) != NULL) { free(x); } } C was so primitive already when compared against Turbo Pascal 6.0
- Yacoby 12y agoTotally worse. free(NULL) preforms no action so there is no requirement for the if statement. ;)
- pjmlp 12y agoExcept free(NULL) behavior is undefined. Have you ever bothered to read ANSI C specification? EDIT: Well it appears my recollections of ANSI C have faded away and free(NULL) was actually defined in ANSI C89.
- pjc50 12y agoWrong, it's defined: http://stackoverflow.com/questions/6084218/is-it-good-practice-to-free-a-null-pointer-in-c http://stackoverflow.com/questions/6084218/is-it-good-practi... You didn't say which version of the ANSI C specification.
- masklinn 12y ago> You didn't say which version of the ANSI C specification. Which does not matter because all of them clearly define the behavior of free(NULL). The language has been the same since C89[0]: > The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs. I'm guessing pjmlp confused free(NULL) which is defined and double free which is UB: > if the argument does not match a pointer earlier returned by the calloc , malloc , or realloc function, or if the space has been deallocated by a call to free or realloc , the behavior is undefined. and didn't "bother to read the ANSI C specification" because he was so certain of what he misremembered. [0] http://port70.net/~nsz/c/c89/c89-draft.html#4.10.3.2 http://port70.net/~nsz/c/c89/c89-draft.html#4.10.3.2
- pjmlp 12y ago> and didn't "bother to read the ANSI C specification" because he was so certain of what he misremembered. Yes, it appears my recollections of ANSI C have faded away.
- masklinn 12y ago> Except free(NULL) behavior is undefined. > Have you ever bothered to read ANSI C specification? You mean the one that states > The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs. ?
- caf 12y agoIt's been defined ever since the original ANSI C, which said this in the definition of free(): If ptr is a null pointer, no action occurs.
- blt 12y agobut it probably costs a stack frame right? ;)
- cbd1984 12y agoThe source code to the original Bourne shell did that and a lot worse. It became one of the inspirations for the IOCCC (International Obfuscated C Code Competition). http://www.ioccc.org/faq.html http://www.ioccc.org/faq.html (What that FAQ doesn't mention is the real reason the Bourne shell deserved to be in the IOCCC: The way it allocated memory. It trapped SIGSEGV (the signal the kernel sends you when you've provoked a segmentation violation or segfault by trying to access memory you don't own) so it would know when to request more RAM from the OS. This later became a problem for people looking to port the Bourne shell, for example to the Motorola 68000 CPUs which powered the first generation of Unix workstations. http://www.in-ulm.de/~mascheck/bourne/segv.html http://www.in-ulm.de/~mascheck/bourne/segv.html )
- anatoly 12y agoThat's an amazing story, thanks! This is the place where it catches the fault: http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh/fault.c http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/...
- 0942v8653 12y agoHere's the IF/FI #defines: http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh/mac.h http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/...
- thaumaturgy 12y agoHah, yep. I remember giving that a whirl not long before I gave up on Pascal, and looking at my screen and being completely horrified by the result.