pavel
Or you can use cpp 23 with standard functions)
İbn
std::pair
Can you do it please ?
pavel
Pointer if just a pointer, it doesn't care how much elements it point to. Pointer to 2 elements has the same value as pointer to 100500 elements
pavel
You can return std:: vector if you need return sone variable length array
%Nikita
Can you do it ?
static int out[2]; int *returnTwoValues(void){ int x = 5, y = 10; out[0] = x; out[1] = y; return out; } int main(void){ int *res = returnTwoValues(); printf(“returned %d %d”, res[0], res[1]); return 0; }
pavel
Our use pair if need to return 2 values, or make your custom structure and return anything
pavel
A variant too
No, variant works another way
%Nikita
No, variant works another way
I mean you can do this way too =)
Talula
How can I return two values ​​.. or not possible?
By making two different functions... or by passing address of the variable. #include <stdio.h> int main() { // Write C code here int v; int r = value(&v); printf("%d, %d",v,r); return 0; } int value(int *a) { *a = 100; return 200; } The variable
Talula
in C language
That is C
Talula
you are returning just one value (200) tho
Yeah and you can get the other 100 from changing the value at the pointed address... so you get two values.
klimi
Yeah and you can get the other 100 from changing the value at the pointed address... so you get two values.
but that's not returning it... as far as i understand, the question was how to return 2 values
pavel
It's all sounds pretty strange)
klimi
that's not returning 2 values, you are just writing to global variable
pavel
Formally you can't return 2 values. You can return only one value, which contains any number of values inside
pavel
Or you can pass some pointers to function and then fill their values
klimi
well yeah, but at the end of the day you are returning one object
pavel
Anyway C don't care what you call "return"
klimi
you could say that while returning uint8_t that you are in fact returning 8 bools but idk
klimi
it even has return keyword
pavel
For example struct A {int f0; int f1}.... A a; a.f0 = 1; a.f1 = 2; return a;
pavel
You return only one value, a, formally
pavel
But have 2 in practice
pavel
it even has return keyword
It has, but it nothing more than write some value to special register and break. As well as you can write to special register without this keyword (by fill some value in function arguments passed as pointers )
Talula
well yeah, but at the end of the day you are returning one object
Do you know any way to return 2 objects in C, I think you can do it in Python
Dhanraj
/start@MissRose_bot
Dhanraj
/start@MissRose_bot
Leovan
Leovan
We cant return more than 1 value in C because stdcall convention use only one EAX register to return and other registers values will be resumed to their values before calling
pavel
I think python just cast 2 returned values to list
Python is very different language . In modern c++ you can do almost the same
Hussein
Do you know any way to return 2 objects in C, I think you can do it in Python
return a pointer from a static array contain two values
Hussein
If you want to return two different data types then return a pointer to a static array of two unions
Hussein
and you get a functionality very similar to python
pavel
Why don't just make a structure?
pavel
Or better don't use C. It's ded)
Hussein
Why don't just make a structure?
yeah this also can work if it is “static”
Hussein
Or better don't use C. It's ded)
then Linux , Mac OS and Windows are dead
pavel
Any alternatives? :d
Sure, at least C++. If you are not Linux kernel developer
pavel
then Linux , Mac OS and Windows are dead
Linux Mac and Windows have much updates. C - not
Hussein
And without static
yes you are right because it is not a pointer. sorry
Hussein
Linux Mac and Windows have much updates. C - not
with C optimisations are lot more easier to implement in terms of compiler development also you get faster compile time a very good example is that firefox takes a whole night to compile while the linux kernel a much larger project takes only few hours
Leovan
Every language for its task!
pavel
Every language for its task!
I write firmware for MCU on c++ 17
Hussein
I’m not saying C++ is bad I’m just saying that until this day there is many (not the majority of devs) prefere C over C++ because C++ tend to get ugly with OOP when a project start to grow
İbn
no, i don't think there is a way
What if we use (if), if it is checked, it will return a value, and if not, it will return a second value. !!?
klimi
Hussein
I’m not saying C++ is bad I’m just saying that until this day there is many (not the majority of devs) prefere C over C++ because C++ tend to get ugly with OOP when a project start to grow
take the V8 engine for example you are better off with creating your own engine than to modify it and fork it. it is completely an ugly yet powerful mess this happens to C projects as well but with C simplicity in terms of syntax and program structure helps to ease growth of projects
İbn
about (structer)?
No .possible ...right ?
klimi
No .possible ...right ?
I don't understand; what a s (structer) ?
İbn
structures
klimi
oh you mean struct :D
İbn
Yeah
klimi
then you will be returning one value and that is one structure
pavel
then you will be returning one value and that is one structure
I don't understand already why do you want return 2 value here
klimi
I don't understand already why do you want return 2 value here
That was the question asked here: how to return 2 values
klimi
It could be. my answer to that was that you cannot return 2 values
Roxifλsz 🇱🇹
Bruh your channel has nothing related to C
Roxifλsz 🇱🇹
This is basically offtopic
Fetheddine
Good morning everyone