« first day (1328 days earlier)      last day (1516 days later) » 

user6461957
12:00 AM
Yeah, but it is due to how memcpy works internally, I believe.
 
its works!
 
user6461957
It needs to have a starting address and how many bytes you want to copy from another address to that starting address.
 
user6461957
 
memcpy(ptr+4, &ptr, sizeof(&ptr));;

auto* address = reinterpret_cast<block>(readBuffer(ptr+4));
writeBuffer(address, 103256483);
a3 91 27 06 50 5e 6e 00 00 00 00
062791A3 = ‬103,256,483‬
 
user6461957
Yeah, with
memcpy(ptr+4, &ptr, sizeof(&ptr)); you are saying: "I want to copy the contents of ptr, starting from &ptr to the location ptr + 4"
 
12:03 AM
yeah that is exactly what I am trying to do
 
user6461957
Wait
 
user6461957
You have overlapping memory locations...
 
user6461957
Or potential overlapping memory locations...
 
how so?
also what is the cost of memcopy
 
dude it's a freaking ghost town in these chat rooms on Friday evening
wtf lol
 
user6461957
12:05 AM
You have to be extra careful with memcpy. Use memmove if you want to be safe it is a bit more expensive (due to a syscall), but it will make a copy out of your original object.
 
user6461957
@JossieCalderon I can't sleep despite working 10 h per day, 6 days a week
 
I cant be safe because it has to be fast
 
user6461957
Then be careful using memcpy and everything will be fine
 
Thats good because that means you have a problem, which you have identified, if it is a problem.
 
user6461957
(I have a feeling the mods will hate me after this nighty night.)
 
12:08 AM
lol thanks man I really appreciate the help
 
user6461957
your welcome! :)
 
user6461957
Oh, I forgot to help the other guy with the palindromes...
 
user6461957
well, I guess I am getting too tired right now... I need rest. @JossieCalderon thanks for the sleeping pills :P
 
user6461957
12:31 AM
Well no still can't sleep. NVM
 
@d03 where you from?
 
user6461957
Germany
 
12:51 AM
@d03 L-Theanine, or GABA. Get it at your local Walmart
or Amazon
etc.
fall asleep within 30 mins, uninterrupted sleep for 8 hrs bro
 
1:04 AM
lol you sound like a sales man
I dont think the have walmart in DE
 
I am a sales man...
 
you working for big pharma lol?
 
@chewbapoclypse Just order Amazon then
no LOL
big pharma is stuff that you cant get OTC
 
yeah thats fo sho
 
user6461957
Guys hop over to the Lounge or else mods will be mad at us :(
 
user6461957
1:07 AM
*the mods
 
7:29 AM
implying people still care about this channel ☜(゚ヮ゚☜)
 
 
4 hours later…
11:00 AM
Hey guys, anyone active here?
 
user6461957
11:34 AM
Yeah, sort of...
 
1:37 PM
```
```
const int i=3;
const int* p=&i;
int* k=const_cast<int*>(p);
```
Different pointer from p is stored in k, but the value stored at these pointers is the same.
Is my reasoning correct ?
 
user6461957
2:00 PM
Let my overworked, sleep deprived brain help you: yes.
 
2:24 PM
Should I trust your overworked sleep derived brain ?
 
user6461957
2:41 PM
Probably not, wait for the higher-ups!
 
Sure, thanks anyway.
 
3:02 PM
Another question:
Is there any difference between these function declarations:
int count(int (&arr)[4]){...} and int count(int arr[4]){...}
 
 
1 hour later…
user6461957
4:14 PM
@GRRohman A reference to a 4 element sized array of integers and an array of 4 element sized integers. C and C++ will "treat" arr as a pointer anyway in that case. You cannot pass arrays to functions (IOW: the array's size gets lost along the way).

https://godbolt.org/z/yAy_fd

Functions f and h are equivalent, a reference practically boils down to a const pointer, but a reference takes care of the dereferencing * and referencing & of an object automatically.

Hope it helps! :)
 
user6461957
(Dear mods, please don't kill me, I have sinned again with the "func... func... func... functional equivalencccc... ccy".)
 
user6461957
I find returning n-sized arrays and arrays of function pointers to be ugly in C, have a look:

int (*f[42])(); // 42 func ptrs

int (*f)()[42]; // func ptr pointing to a func that returns a 42 element sized array of integers.
 
hold on a sec
so f and h are equivalent
to a certain point
 
user6461957
"functionally equivalent"
 
but what about function g ?
 
user6461957
4:27 PM
(God I am risking getting shot by the mods over this)
 
bahhahaah
 
user6461957
It will be "treated" as a pointer.
 
so is it also "functionally equivalent" with f and h ?
 
user6461957
(You can't pass whole raw arrays to a function, C does not support it, C++ also doesn't support it, unless you use std::array)
 
Ok I get that. I'm asking whether function g works the same as f and h.
 
user6461957
4:32 PM
Yes, the assembly output suggests that too.
 
And it would work the same no matter what the body of the function looked like ?
functions*
 
user6461957
Well, you need to take care of the dereferencing yourself in function h. Otherwise yes, I would treat them as equivalent.
 
That is what I was looking for. Thanks for the wholesome answer.
 
user6461957
You're welcome!
 
user6461957
6:09 PM
Though, you can pass raw arrays to functions in C and C++ sort of:
void f(int (*p)[3]) // the brackets are important!
void f(int *p[3])

The first one means: a pointer to an int array of size 3. The second means: an array of three integer pointers.
 
user6461957
But I find the syntax very confusing and I often get hung up on it...
 
user6461957
Or rather you can enforce the limitation to arrays with certain dimensions.
 
@d03 yo!
 
user6461957
As previously stated, returning arrays with a certain size is also possible:

int (*f(int (*x)[3]))[3]
 
user6461957
Yes?
 
6:21 PM
you remember yesterday where I was writing the addresses into an array?
 
user6461957
Yep sort of. What happened to it? Is it alive?
 
yeah working like a charm
 
user6461957
Phew! Hehe... :)
 
but I had a question that I wanted to pick your brain about
 
user6461957
Yeah give me more of it. Feck my brain.
 
6:23 PM
haha
so the whole point of storing it into the array is to retrieve, an use it as a pointer to that location
when reading it back out what do you think a function sure return it as? a unsigned char*?
 
user6461957
char * would break portability due to potential different byte orderings per machine.
 
user6461957
Or
 
user6461957
You handle that byte ordering somehow and then you will be fine
 
user6461957
char * means make that thing byte addressable.
 
user6461957
Maybe using fixed size types will help? Things like uint64_t and uint32_t?
 
user6461957
6:27 PM
But what if 128 bit machines will arrive, then you need to take care of that too...
 
user6461957
So either way you probably should take care of the byte ordering if you don't want to loose portability or you explicitly state that your program only works for little endian machines etc.
 
user6461957
Clear?
 
well it needs to be byte addressable(or at least I believe it does) since its just another location in that same array of bytes
 
user6461957
Sure, but on a big endian machine your results might differ.
 
wouldn't on a BE it be saved in the correct order?
 
user6461957
6:31 PM
 
I see what you mean
 
user6461957
How?
If your 4 byte integer is stored little endian in memory, i.e., LSB first from lower to higher addresses (downwards) and on big endian it is all reversed, then you need to take care of it.
 
so how does one account for the ordering when saving mem
 
user6461957
Well, you need to detect on what machine you are and then access it accordingly.
 
user6461957
6:36 PM
The basic idea goes like this: You have a hexadecimal integer of type int32_t, so 0xAABBCCDD will be stored differently on big- and little endian machines.
If AA has a lower address, then it is big endian etc.
 
user6461957
Then if you know you are big endian for example, you account for that by accessing the higher addresses first.
 
user6461957
Or just store it in a int64_t integer somehow, but then if 128 bit machines arrive you will either need something like int128_t (if it even exists) or you have to make that clear somehow.
 
user6461957
What if 256 bit machines come up?
 
that sounds like a problem for the future version of oneself
 
user6461957
What if 1024 bit machines emerge?
 
6:42 PM
:D
 
 
2 hours later…
9:04 PM
I have a question about class-syntax. This here github.com/Chrinkus/stroustrup-ppp/blob/master/chapter09/… is compilable and runs, but is not flawless(but that isn't what I want to ask). I thought you have to atleast declare memberfunctions in the class itself like here codereview.stackexchange.com/questions/157881/… (first answer) and then define them later. Can someone enlighten me here?
In the first the class-body doesn't mention all operators, but it still somehow works...
 
nwp
The ones with Rational:: are member functions and must be declared in the class, the other ones are not. You can look up which operators can/must be implemented as members or non-members.
 

« first day (1328 days earlier)      last day (1516 days later) »