Jussi
or then pack the array into a struct
Jussi
struct my_array { int* array; int size; } and edit the my_array.size property
Jussi
but I would use std::vector, it would just save you so much time and hassle
Anonymous
Using c-style arrays is not a cpp way
Anonymous
Just wanted to say "without STLs"
Anonymous
and nothing else
Anonymous
Why do you need it?
Anonymous
Just wanted to know
Anonymous
not needed
Anonymous
Also, sometimes I've seen someone do return (int*) arr; What does that mean and why is it necessary
Anonymous
auto func() { std::array array_to_return = {1, 2, 3}; return array_to_return; }
Jussi
it casts arr to be a pointer to integer
Jussi
it is needed in C++
Anonymous
but if we just do return arr
Anonymous
does it make any difference?
Anonymous
I read that array decay to pointers
Вадим
can i include library with cmake console parameters, without cmakelists?
Jussi
int* fun(void* arr) { return arr; } compiles in C, not in C++
Anonymous
You cannot return c-style array from a function using return statement
Anonymous
int* fun(void* arr) { return arr; } compiles in C, not in C++
That is because you have passed arr as void pointer, so in that case you definitely need to use int*
Jussi
int* fun(void* arr) { return (int*)arr; } compiles in C and C++
Anonymous
yes that is right
Jussi
int* fun(void* arr) { return (int*)arr; } compiles in C and C++
but is bad practise because C++ has its own type-casting operators
Anonymous
Anonymous
But that is not my question. I mean, would this make any difference from int* fun(int arr[]){ int arr[] = {1,2,3}; return arr; } int* fun(int arr[]){ int arr[] = {1,2,3}; return (int*)arr; }
Anonymous
I guess these are same
Anonymous
Anonymous
You have redefinition of arr
Anonymous
which one doesn't compile and which one does?
Anonymous
and what is the difference?
Anonymous
So what should be the correct way to pass the compilation
Anonymous
https://www.geeksforgeeks.org/c-plus-plus/
Anonymous
You have two definitions of arr
Anonymous
to or two?
Anonymous
Read Stephen Prata, C++ Primer Plus
Anonymous
to or two?
Two of course, sorry
Anonymous
Anonymous
2 defintions of what?
Anonymous
Of arr, god
Anonymous
yes
Did you read it?
Jussi
XD
Anonymous
unfortunately NO
Anonymous
but 2 definitions of what?
Anonymous
So read it
Jussi
but 2 definitions of what?
parameter arr and local definition of arr
Anonymous
Jussi, help me
Anonymous
I'm really to pass those parameters
Jussi
it is funny to help people here once a month :D
Anonymous
I don't have parameters
Anonymous
Read Prata
Jussi
:D
Anonymous
Jussi
int* fun(int arr[]){
Anonymous
i didn't want to pass parameters
Jussi
int arr[] is a parameter
Anonymous
forgot to remove the parameters
Anonymous
just copy pasted it
Вадим
guys, who can say, what a best free book for sdl2?
Anonymous
int* fun(){ int arr[] = {1,2,3}; return arr; } int* fun(){ int arr[] = {1,2,3}; return (int*)arr; }
Anonymous
tell the difference
Jussi
no need to tell difference, both are wrong
Anonymous
why
Anonymous
arr would mean address of 1st element