Only I think that C++ popularity.. Has gone down?

Pages: 123
Aug 19, 2015 at 11:12am
"inline" instructs the compiler on how to produce symbols for the linker. It has nothing to do with function inlining.
C++ compilers are probably the most aggressive when it comes to function inlining, and they're most certainly more aggressive than JITs, which have soft real-time deadlines to meet.


you still have to deal with it in c++, and not in C#

If you write code assuming the wrong parameter-passing mode you not only will write badly-performing code, but also probably incorrect code. If the code is incorrect then it doesn't make sense to talk about its performance.


thats right, and this one reason why people afraid to use C++,and use(learn) languages like C# + makes C++ a more difficult language than C#(and thats actually what i want to say)
Last edited on Aug 19, 2015 at 11:38am
Aug 19, 2015 at 11:39am
you still have to deal with it in c++, and not in C#
Deal with what? Inlining is automatic. If your program doesn't contain a single instance of the keyword, functions may still be inlined.
inline has no effect on function inlining; it's used to prevent duplicate symbols when a function is defined in a header.

thats right, and this one reason why people scared of C++, and use languages like C#.
Who said those mistakes can't be made in C#?
1
2
3
4
5
6
7
8
void IWontModifyTheArgument(SomeList l){
    l.Add(foo); //Whoops! Forgot everything is passed by pointer by default!
    Process(l);
}

void IWillModifyTheArgument(SomeList l){
    l = new SomeList(); //Whoops! Forgot everything is passed by pointer by default!
}


EDIT: But of course:
1
2
3
4
void IWontModifyTheArgument(int i){
    i = 42; //OK!
    Process(i);
}
Last edited on Aug 19, 2015 at 11:45am
Aug 19, 2015 at 11:49am
Deal with what? Inlining is automatic. If your program doesn't contain a single instance of the keyword, functions may still be inlined.
inline has no effect on function inlining; it's used to prevent duplicate symbols when a function is defined in a header.


inline key word: it has an performance effect:
https://isocpp.org/wiki/faq/inline-functions#inline-and-perf

Bjarne Stroustrup comment in an interview:

My own rule of thumb is to use inlining (explicitly or implicitly) only for simple one- or two-line functions that I know to be frequently used and unlikely to change much over the years. Things like the size() function for a vector. The best uses of inlining is for function where the body is less code than the function call and return mechanism, so that the inlined function is not only faster than a non-inlined version, but also more compact in the object core: smaller and faster.


If your program doesn't contain a single instance of the keyword, functions may still be inlined.

Yeah, that's what compiler optimization do, but with inline you can help the compiler and with forceinline sometimes force him to do it.

Who said those mistakes can't be made in C#?

I still think C# is easier to use than C++, especially if you start programming.
Last edited on Aug 19, 2015 at 11:50am
Aug 19, 2015 at 12:06pm
Modern compilers no longer need help to figure out function inlining. Hence the point of having compiler extensions that force a function to be inlined (generally because the function does some black magic of some sort). Nowadays they completely ignore the keyword.

http://stackoverflow.com/questions/1759300/when-should-i-write-the-keyword-inline-for-a-function-method.

I still think C# is easier to use than C++
That's a separate discussion from whether a C++ program written as if it was C# will perform better than a straight C# program.
Aug 19, 2015 at 12:21pm
Modern compilers no longer need help to figure out function inlining

Thats not true, they might be better, and always get better, but never will do it 100% perfect. Also the decision if something should be inlined is different on each compiler.

Compiler ignore inline if something just can't be inlined or the compiler thinks it would be better not to inline it. But as far as i know its also possible to force inline, even if the compiler "says no" gcc provide __attribute__((always_inline)) and win compiler __forceinline

i like this sentence from the ISO:

There are no simple answers: You have to play with it to see what is best. Do not settle for simplistic answers like, “Never use inline functions” or “Always use inline functions” or “Use inline functions if and only if the function is less than N lines of code.” These one-size-fits-all rules may be easy to write down, but they will produce sub-optimal results.





Last edited on Aug 19, 2015 at 12:26pm
Aug 19, 2015 at 12:46pm
Automatic inlining (and other global optimisations) are typically not performed by default across translation units - for instance calls to library code. Compilers can't optimise calls to functions that they can't see.

For automatic inlining to happen with library code, the library must be built with support for link-time optimisation/code generation. This is typically not the defaut; programmer intervention is required.
With g++: http://www.cplusplus.com/forum/general/160543/#msg819315
Aug 19, 2015 at 12:52pm
There are two basic approaches:
1. Select the most appropriate tool for each job. You have to know many tools.
2. Use the same tool for every job. Gets the job done, somehow.

An example of such considerations:
https://www.reddit.com/r/linux/comments/2s71i6/how_is_c_on_linux/
Aug 19, 2015 at 1:02pm
Automatic inlining (and other global optimisations) are typically not performed by default across translation units

as an anecdote, I was caught by surprise by IBM XL C++ a few years ago, which performs link-time optimization (with inlining and everything) by default when optimizations are enabled.

inline has no effect on function inlining; it's used to prevent duplicate symbols when a function is defined in a header

it's a bit of a chicken-and-egg situation: for compile-time inlining, the function definition needs to be available in the translation unit as it is being compiled. To reuse functions across translation units while making compile-time inlining possible, their definitions have to appear in more than one translation unit, and to do that, they have to be inline (explicitly or implicitly)
Aug 19, 2015 at 1:08pm
closed account (1vD3vCM9)
Jesus people, already second page :D
Last edited on Aug 19, 2015 at 1:11pm
Aug 19, 2015 at 1:15pm
closed account (1vD3vCM9)
BTW guys, I think I can move on to graphics..
But my friend tells me I need to learn databases.
Although I can't find good tutorials for SQL!
Can you help me with that?
Aug 19, 2015 at 1:21pm
what do you mean by graphics?
Aug 19, 2015 at 1:22pm
closed account (1vD3vCM9)
What I'll tell you.. I guess a graphics library.
Maybe SDL
Aug 19, 2015 at 1:55pm
Learning SQL is a good idea, since databases are used nearly everywhere, but has nothing to do with C++. You might also want to learn how to create a database connection and how to execute SQL through C++ or any other language you want.

Maybe SDL

So you want to makes games?
Aug 19, 2015 at 1:59pm
Compiler ignore inline if something just can't be inlined or the compiler thinks it would be better not to inline it.
If the compiler can choose not to inline an inline function, how is that different from the keyword being ignored for the purposes of inline decision?

But as far as i know its also possible to force inline, even if the compiler "says no" gcc provide __attribute__((always_inline)) and win compiler __forceinline
Those are compiler extensions, not exactly part of C++. Again, if inline actually had an effect on whether a function is inlined, why would these extensions be needed?

Automatic inlining (and other global optimisations) are typically not performed by default across translation units - for instance calls to library code. Compilers can't optimise calls to functions that they can't see.
What do you mean by "by default"? For example, VS by default turns on link-time code generation for release builds, which performs optimizations across translation units.

it's a bit of a chicken-and-egg situation: for compile-time inlining, the function definition needs to be available in the translation unit as it is being compiled. To reuse functions across translation units while making compile-time inlining possible, their definitions have to appear in more than one translation unit, and to do that, they have to be inline (explicitly or implicitly)
I agree, but Sleicreider is arguing something different. Namely, that a C++ programmer needs to make decisions about inlining for it to be performed at all:
Sleicreider wrote:
its not incorrect at all, if you would write code in C++ like you would in any other language(lets take java,c# since they are "similar") and don't care about pointers, references, inlines (which are handled in java and c# in the background) , your code probably will be "slow"
Aug 19, 2015 at 2:14pm
closed account (1vD3vCM9)
Yes, I want to learn how to make games.
But how can I connect SQL to C++???
I still haven't found an answer anywhere!
Aug 19, 2015 at 2:18pm
If the compiler can choose not to inline an inline function, how is that different from the keyword being ignored for the purposes of inline decision?


In somecases the compiler might decide to not inline something (as already mentioned compilers do a great job, but aren't 100% perfect), but with the inline hint there is a chance the function still gets inlined.

Those are compiler extensions, not exactly part of C++. Again, if inline actually had an effect on whether a function is inlined, why would these extensions be needed?


Some programmers think forceinline is actually bad, because inlining functions which shouldn't be inlined make things slower and bigger, therefore the c++ keyword inline is the safer solution, where the programmer and compiler are working together, and not forcing the compiler to something.


Yes, I want to learn how to make games.
But how can I connect SQL to C++???
I still haven't found an answer anywhere!


First you might want to learn how to create a database (for example mySQL)
and the SQL commands to create Database, Enitites.

Maybe someone else can show you an example how to connect C++ with mysql database, but there is a lot of code you can find with google.
Last edited on Aug 19, 2015 at 2:23pm
Aug 19, 2015 at 2:27pm
closed account (1vD3vCM9)
Learning SQL is hard, but ok
Aug 19, 2015 at 2:34pm
Learning how to make games is harder, especially if you want to deal with graphics your self(OpenGL, DirectX).

I'm not sure about the w3schools tutorials, but it might be a start:
http://www.w3schools.com/sql/default.asp
Aug 19, 2015 at 2:39pm
closed account (1vD3vCM9)
Thanks mates.
Aug 19, 2015 at 2:56pm
> What do you mean by "by default"?

By "by default", I mean by default.

Read the manual/documentation; you would learn what options are on by default.

Here are a few examples:
Microsoft: (Specify Floating-Point Behavior) /fp:[precise | except[-] | fast | strict ] precise is the default.
https://msdn.microsoft.com/en-us/library/e7s85ffb.aspx

/GL (Whole Program Optimization) Whole program optimization is off by default and must be explicitly enabled.
https://msdn.microsoft.com/en-us/library/0zza0de8.aspx

GNU: -fgcse-las Not enabled at any optimization level.
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options
Pages: 123