Anonymous
An simple example
Anonymous
And for more precision: #include <stdio.h> #include <time.h> int main() { struct timespec t_start = {0,0}, t_final = {0,0}; clock_gettime(CLOCK_MONOTONIC, &t_start); int i = 0; for (; i < 20000000; i++); clock_gettime(CLOCK_MONOTONIC, &t_final); printf("Total: %.8f seconds\n", ((double)t_final.tv_sec + 1.0e-9*t_final.tv_nsec) - ((double)t_start.tv_sec + 1.0e-9*t_start.tv_nsec)); return 0; }
Zuka
Just curious...
Zuka
Out of the topic question...
Zuka
Do we have any BTC or ETC or LTC traders here?
Zuka
Or anyone interested?
Zuka
Zuka
Anonymous
Hi
Zuka
Hey
ENOENT
Uh so I usually don't deal with big C++ projects
ENOENT
I modified some stuff and now the class is abstract
ENOENT
any way I can figure out what it thinks I have not implemented?
ENOENT
or at least that's what I presume "invalid new-expression of abstract class type" means in this case
Hussain
Hello
Anonymous
Hello
Hello
Hussain
All people here have experience with. C /c++ ?
Hussain
Because I know just java
Anonymous
as the group name, c/c++ dev or newbies
Anonymous
Hello all, some good book to understand github projects in c++?
Anonymous
thanks
Top T : Trollface Was Real
many
Why linus prefers C rather than c++?
David
many
Is oop not appropriate for system programming?
David
Is oop not appropriate for system programming?
The language don't supports it, but you can "emulate" the oop in C
many
I see
many
Why saying "emulate"? Does it mean C is not OOP while C++ is? What makes the difference?
David
C++ have oop properties by design, C not, but you can do things like https://stackoverflow.com/questions/351733/can-you-write-object-oriented-code-in-c
Anonymous
Why linus prefers C rather than c++?
Because C it's more lightweight
Anonymous
OOP is better for high level programming
Anonymous
Like videogames
David
Yes
In the linux kernel they use some oop, https://lwn.net/Articles/444910/
Abde
http://nullprogram.com/blog/2014/10/21/ "C Object Oriented Programming" Tags: #C #OOP
Abde
This might be useful :P
ENOENT
Why linus prefers C rather than c++?
because C++'s design is arguably worse, and the kernel does not really need the additional features C++ provides
David
"d/ce b/n" ?
ENOENT
b/n was the wifi standard
Maksym
Hello gues! There are some peoples who use juce for creating GUI?
many
Passing pointer is passing an address. Passing by value is passing a value to certain memory address. What is the computer doing when passing by reference? What is being passed?
Russell
A pointer
Russell
A reference is the same as a pointer when it's compiled
many
Then why people prefer passing reference to a function?
Hafiz Hilman
As far as I know, it is because it is more efficient. You are essentially passing the same instance of an object to the function. Let say u wanna pass an instance of a class to the function. If u pass that instance by value to a function, the program will need to create the exact copy of that instance to be used by the function. So, u will have two same instances of an object. This could be an expensive process. But if u pass a reference, the computer will just need to create/copy the pointer to the instance and use the instance itself. No need for that possibly expensive copying process. Hope u understand this.
many
Then what's the difference between passing pointer and passing reference?
Eu
for me, the most important difference is that you cannot do pointer arithmetics with references
Eu
so security++ optimization_possibllities++
David
for me, the most important difference is that you cannot do pointer arithmetics with references
also, you don't need to check if ptr == nullptr when passing a reference
Eu
For small types like int32, i think it's faster to copy than using pointers (and more clean)
for functions arguments, stack alignment will be 64 bits (in x86_64), so it's the same price.
Eu
sorry, I read really bad your question :) Damn multitasking! It's cheaper to copy because ptr/reference indirection
Eu
but compiler should be able to optimize it pretty well, i.e., convert int& to int, unless it belongs to library api or smth similar
Eu
expanding a little more the answer, references are usually implemented via pointers, so for the generated code should be the same BUT the restrictions about use allows the compiler generate better warnings & better code. It's the same case with const or restrict, the code with no optimization should be the same BUT the compiler has more context information about what you want to do
Russell
One minus with references is that it's not transparent when you're calling a function that that value could be mutated.
Russell
(which is why in the google style guidelines they entirely disallow non-const references)
many
For fast accessing elements and low memory usage: bool[10] or a ten-digit int?
correctmaninwrongplace
Its a binary number?
correctmaninwrongplace
And what will you do with it?
Eu
it's an array of 10 bools
ENOENT
guessing array of bools is faster, but you'll have to actually measure
ENOENT
unless your array is large enough to not fit in cache perhaps
ENOENT
but generally don't worry about performance unless you know it's a bottleneck
many
Its a binary number?
Yeah you're right. It should be a 10-bit integer
correctmaninwrongplace
Probably The array, but you probably will need to implement arithmetic
ENOENT
it's an array of 10 bools
oh I didn't read this if it's just 10 bools don't even bother asking, go with an array
ENOENT
now, if it was a 100000 bools, then it would be worth worrying about performance
.
guys i am stuck with some c++ code....i am trying to work out the implementation of a public member function called "getPassengers()".....lemme send pics asap
.
this is what i have done so far
.
thats what i am supposed to do
.
thats the class
correctmaninwrongplace
this is what i have done so far
I think you forgot +=, in the inner loop you have =, you should have += to concatenate