Thread overview | |||||
---|---|---|---|---|---|
|
October 25, 2013 Just noticed something interesting in the std.allocator source... | ||||
---|---|---|---|---|
| ||||
Just noticed something interesting in the std.allocator source, right at the very bottom. An EOF and some code? Does the compiler stop at the EOF? If so why add code beyond that? Also version(none), eh? https://github.com/andralex/phobos/blob/allocator/std/allocator.d#L4071 What's going on there? ... __EOF__ version(none) struct TemplateAllocator { enum alignment = platformAlignment; static size_t goodAllocSize(size_t s) { } void[] allocate(size_t) { } bool owns(void[]) { } bool expand(ref void[] b, size_t) { } bool reallocate(ref void[] b, size_t) { } void deallocate(void[] b) { } void deallocateAll() { } void[] allocateAll() { } static shared TemplateAllocator it; } |
October 25, 2013 Re: Just noticed something interesting in the std.allocator source... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | On Friday, 25 October 2013 at 16:03:24 UTC, Gary Willoughby wrote: > Just noticed something interesting in the std.allocator source, right at the very bottom. An EOF and some code? Does the compiler stop at the EOF? If so why add code beyond that? Also version(none), eh? > > https://github.com/andralex/phobos/blob/allocator/std/allocator.d#L4071 > > What's going on there? > > ... > __EOF__ > > version(none) struct TemplateAllocator > { > enum alignment = platformAlignment; > static size_t goodAllocSize(size_t s) > { > } > void[] allocate(size_t) > { > } > bool owns(void[]) > { > } > bool expand(ref void[] b, size_t) > { > } > bool reallocate(ref void[] b, size_t) > { > } > void deallocate(void[] b) > { > } > void deallocateAll() > { > } > void[] allocateAll() > { > } > static shared TemplateAllocator it; > } Yeah, it sets the lexer to the end of file so it stops. See Special Tokens section: http://dlang.org/lex.html Andrei is using it to include a pattern of the general structure you'd need to write your own allocator that the compiler doesn't even bother looking at. He could have commented it out too. The version(none) also accomplishes this. __EOF__ just makes it so the compiler doesn't even bother looking at it (you can shave a few microseconds off your build time!) |
October 26, 2013 Re: Just noticed something interesting in the std.allocator source... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | as replied, version(none) allows removing some code from build but it still parses and spew errors in it, there is also version(all) to re-enable code. |
Copyright © 1999-2021 by the D Language Foundation