Earlier quoted context omitted.
Agree except the last example - the clarity of intent that you want a conditional compilation is lost. Also, non-optimized debug builds are affected.
I think it was RMS who argued that conditional compilation should be considered harmful in general. Code that you put in an inactive #if(def) block will not be maintained, and is basically guaranteed to rot. If it's needed in the future, it'll likely have to be rewritten from scratch. According to this stance, any code that's suppressed by the C preprocessor should either be written in an if {} statement so that it w…
Learning that you can use unions in C for grouping things into namespaces
111–120 of 150 posts
Re: Learning that you can use unions in C for grouping things into namespaces
#112Anonymous nested structs are also quite useful for creating struct fields with explicit offsets: #include #include #define YDUMMY(suffix, size) char dummy##suffix[size] #define XDUMMY(suffix, size) YDUMMY(suffix, size) #define PAD(size) XDUMMY(__COUNTER__, size) struct ExplicitLayoutStruct { union { struct __attribute__((packed)) { PAD(3); uint32_t foo; }; struct __attribute__((packed)) { PAD(5); uint16_t bar; }; str…
Anytime macros are used for metaprogramming, it's time to reach for a more powerful language.
A macro is effectively preprocessing facilitated by the language. You could always preprosess externally if you wanted, and there's nothing stopping you from doing that in the "Powerful Language (TM)" either.
Now whether people use macros and preprocessing usefully is another question, but not one to which the answer is "abolish macros for more language features". When used correctly, macros ARE power.
Re: Learning that you can use unions in C for grouping things into namespaces
#113Earlier quoted context omitted.
> Conditional compilation is an optimization, not a semantic intent. Why can't it have semantic intent? I frequently use it for cross-platform adjustments, and those don't usually compile on the defined-away platform.
> those don't usually compile on the defined-away platform Then you're doing it wrong :-/ All these can be made to work. P.S. compiling successfully is not the same thing as linking successfully. Think stubs and deciding which files to link together.
Re: Learning that you can use unions in C for grouping things into namespaces
#114Earlier quoted context omitted.
> those don't usually compile on the defined-away platform Then you're doing it wrong :-/ All these can be made to work. P.S. compiling successfully is not the same thing as linking successfully. Think stubs and deciding which files to link together.
Making it clear in the code itself that something is platform specific is useful as well. Also, I'd say such stubs and extra files would clutter the project.
Rewriting it the way I suggest tends to force a cleanup of all that. You'll like the results.
BTW, if you want to try transitioning to the next level, try getting rid of all the `if` statements, too!
Re: Learning that you can use unions in C for grouping things into namespaces
#115Earlier quoted context omitted.
The optimizer will delete bar() if FOO is a manifest constant that is not 3. Yes, but the compiler won't delete it and complain if bar is not defined. if constexpr is not a direct replacement for if macro
> the compiler won't delete it and complain if bar is not defined extern void bar(); will define it to the satisfaction of the compiler. The linker won't complain if the compiler removes the call to it.
void my_bar_class_type::bar(my_bar_type::my_bar_inside_type paramater);
and you are calling something like myObject->bar(mySecondObject.getWhatever());
You have to mock up like everythingRe: Learning that you can use unions in C for grouping things into namespaces
#116Earlier quoted context omitted.
> Anytime macros are used for metaprogramming, it's time to reach for a more powerful language. > I'm referring to both syntax based (AST) macros ... This surprises me greatly. Various lisps are among the most powerful languages I know of and a large part of the reason is macros coupled with their ability to execute arbitrary code at compile time (which itself uses additional macros, which in turn invoke more code, a…
I'm a noob when it comes to Lithp. But I'm told what happens with their macros is the language is fairly unusable until you write lots of macros. The macros then become your personal undocumented wacky language, which nobody else is able to use. I've seen this happen with assembler macro languages, too. > most powerful It's like putting a 1000 hp motor in a car. It's main use is to wreck the car and kill the driver.…
This is not (typically) the case. It would be like saying that you need to write lots of templates to get things done in D. Metaprogramming is certainly very nice to have but it's not a requirement for the vast majority of tasks.
It's important to note that Lisps are an entire family of languages; some implementations are batteries included while others are extremely minimal. Where things can get a bit confusing is that many macro implementations are so seamless that significant pieces of core language functionality are built in them. Schemes tend to take this to an extreme, with many constructs that I would consider essential to productive use of the language provided as SRFIs.
> macros then become your personal undocumented wacky language
That's Doing It Wrong™. You could as well argue to remove goto from a language because sometimes people abuse it and write spaghetti. C++ has operator overloading. D has alias this. If (for example) a DSL is the appropriate tool then being able to use macros to integrate it seamlessly into the host language is a good thing.
Re: Learning that you can use unions in C for grouping things into namespaces
#117Earlier quoted context omitted.
I don’t see the undefined behavior here?
Op probably means cpp, where it is indeed undefined behavior. not sure about c. I doubt that if this would cause a "my game does not work on XXX" though. Is there really a compiler out there that will handle such abuse differently?
Re: Learning that you can use unions in C for grouping things into namespaces
#118Earlier quoted context omitted.
> Anytime macros are used for metaprogramming, it's time to reach for a more powerful language. > I'm referring to both syntax based (AST) macros ... This surprises me greatly. Various lisps are among the most powerful languages I know of and a large part of the reason is macros coupled with their ability to execute arbitrary code at compile time (which itself uses additional macros, which in turn invoke more code, a…
I'm a noob when it comes to Lithp. But I'm told what happens with their macros is the language is fairly unusable until you write lots of macros. The macros then become your personal undocumented wacky language, which nobody else is able to use. I've seen this happen with assembler macro languages, too. > most powerful It's like putting a 1000 hp motor in a car. It's main use is to wreck the car and kill the driver.…
I don't know much about D compile time evaluation. How is it better than macros/templates?
Also, what do you think about Haskell's and Rust's approach of generics with typeclass/trait bounds?
Re: Learning that you can use unions in C for grouping things into namespaces
#119Earlier quoted context omitted.
I'm a noob when it comes to Lithp. But I'm told what happens with their macros is the language is fairly unusable until you write lots of macros. The macros then become your personal undocumented wacky language, which nobody else is able to use. I've seen this happen with assembler macro languages, too. > most powerful It's like putting a 1000 hp motor in a car. It's main use is to wreck the car and kill the driver.…
> BTW, D is the first language of its type (curly brace static compilation) to be able to execute arbitrary code at compile time. It started as kind of "let's see what happens if I implement this", and it spawned an explosion of creativity. It has since been adopted by other languages. I don't know much about D compile time evaluation. How is it better than macros/templates? Also, what do you think about Haskell's an…
CTFE isn't better than templates, it's a completely different tool. CTFE computes a result at compile time as though you had written a literal in the source code. Templates generate blocks of specialized code on the fly based on various parameters (typically types). They solve different problems.
Re: Learning that you can use unions in C for grouping things into namespaces
#120Earlier quoted context omitted.
Can you link to it? We're using expression templates on a new library and I find it useful.
Oh man, you sure know how to drive a stake in my heart! What have I done! Some curses should just not be uttered. I'm not sure where it is on my backups. But it was done just like you'd do it in C++. The same thing, just with D syntax.