static __forceinline or __forceinline static [closed] - c++

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Good morning, this always made me wonder (even tho it doesn't really matter) but which one is the correct way? Or is there none and both ways are fine?
static __forceinline T some_func ( )
or
__forceinline static T some_func ( )

It is important to order modifiers alphabetically, except if you are writing code on the solstice or equinox (during which it angers the sun microsystems god).
Other than that, use whatever order you wish, so long as you are willing to live with the consequences.
Which are none.

As you said yourself, both are legal and their results are identical so it comes down on personal preference.
For what it's worth in most codebases I've worked compiler specific keywords were always used before any standard C++ keywords which makes your 2nd snippet more common.
However as always with code style, just pick one you like most and be consistent. Consistency is what's important.

Related

When is it better to use switch/case over if statements? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 months ago.
This post was edited and submitted for review 5 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have a tendency to use switch statements if I am creating a menu driven program, and I tend to use if statements when I only have a few items. I believe this has to do with the way I was taught in school, but I don't know if that is necessarily the way to go.
Are there vast differences between the two? When should you pick one over the other?
Edit: I should specify, I am mainly concerned with optimization (even if one or the other is only marginally more efficient).
If statements look like if statements. Switch statements look like switch statements. Some compilers may be mildly better at optimizing certain types of switch statements than the equivalent set of if statements, though that won’t be a significant factor in your situations. In cases where the two are both applicable, there are few practical concerns in choosing one over the other.
Use whichever fits your intended coding style better.

Meaning of these particular pointers [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I'm hesitant to consider this a valid question so close or downvote if you wish, I promise not to be offended :-)
I've just been watching Herb Sutter's excellent CppCon2018 talk on making C++ more powerful and simpler at the same time. I'd strongly suggest watching this if you haven't already.
Near the end, he references an xkcd cartoon on pointers, where the three pointers given are suspiciously ASCII in nature(a), usually a sure sign that you've somehow got yourself a corrupt pointer.
The three pointers are 0x3a28213a, 0x6339392c and 0x7363682e, which equate to the three character blocks :(!:, c99, and sch. (though endian issues may reverse the order of the characters).
Does anyone know if there's any significance to these pointers?
(a) Yes, I also noticed the ASCII in Homer Simpson's 3d episode sequence, meaning I've been in this game way too long :-)

Why are standard libraries always so complex? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
this might be a strange question, but I don't quite understand this. When I look at let's say string.h, I really have no idea what I'm even looking at... Maybe I'm just inexperienced or something, but those files look nothing like a header file I've ever written.
I could write my own string implementation and it would be so much shorter and more readable than this file I'm looking at here...
So basically I'm just wondering what's going on here that makes it necessary to write all this long and complex code.
Edit: oke thanks for the responses, I get the point. It's kind of what I expected, but it's nice to get some confirmation:p
Driving a car is (arguably) extremely easy, compared to how complicated an engine looks on the inside.
Libraries such as these are meant to be easy to use, but what's behind the scenes might not always be easy to understand. You're better off using the actual documentation for such libraries.

Should I use std::old_c_functions or just old_c_functions? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I wanna use C libraries such as cstdio and cstdlib, and I can use both:
int i = atoi("123");
or
int i = std::atoi("123");
Both work fine. Which one should I use? Are they equivalent?
For portability, you should use the std versions, for two reasons:
The standard doesn't guarantee that C library functions are dumped into the global namespace; it just allows implementations to do that. This means your code might not compile if you change implementations.
Some functions (not atoi, but mathematical functions, for example) have extra overloads in C++. At least one popular library dumps the C overload into the global namespace, but not the C++ overloads. This means your code might change its behaviour in bizarre and infuriating ways if you change implementations.

Readability: splitting lines of code, should the operator be on the first or second line? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Simple question about formatting code (in my case C++).
If I have a line of code, say:
SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace + IDontActuallyUseVariablesThisLong
Should I split it like:
SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace +
IDontActuallyUseVariablesThisLong
or:
SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace
+ IDontActuallyUseVariablesThisLong
Another example:
foo = bar->baz;
// Should it be:
foo = bar->
baz;
//Or:
foo = bar
->baz;
Do people have a preference when it comes to this? Is it on a case-by-case basis? They both seem equally clear (or unclear) to me, so I was wondering if there are any standard ways of doing it.
Yes, people have preferences about this.
No, there's no standard or consensus agreement. I'm not aware of any especially strong arguments for either side, either.
So like any coding style issue, you can stick with whatever other people who edit the same code have been doing, or just pick one you like.
(I wouldn't even complain about being inconsistent on this issue.)