Shvmtz
Shvmtz
Shvmtz
#include <stdio.h>
int main()
{
return 0;
}
$ size ./a.out
text data bss dec hex filename
1418 544 8 1970 7b2 ./a.out
Shvmtz
#include <stdio.h>
static int i;
int main()
{
return 0;
}
$ size ./a.out
text data bss dec hex filename
1418 544 8 1970 7b2 ./a.out
Hsn
Shvmtz
Shvmtz
Anonymous
Why bss is same after declaring static variable?
This depends on the linker. Could be that the linker you are using puts stuff like ioinit in the bss section. Could be the case that your linker enforces strict alignment requirements between your data and BSS segment and also on the end of BSS segment. Read up your linker docs to find out more info on this.
Anonymous
What is nullptr
artemetra 🇺🇦
What is nullptr
google is your friend
https://en.cppreference.com/w/cpp/language/nullptr
Anonymous
Google keyword "nullptr" got me this https://stackoverflow.com/questions/1282295/what-exactly-is-nullptr quite confusing.
Google keyword "NULL vs nullptr" got me this https://stackoverflow.com/questions/20509734/null-vs-nullptr-why-was-it-replaced quite understandable.
Anonymous
Its not https
Anonymous
Hello
Anonymous 🇪🇦
How can i return a int or a string from the same function?
I'm trying to do it based on if the type is casteable to int (return a int from the function). Else return a string
Anonymous 🇪🇦
int access(const char * name) {
try {
return stoi(variables.at(std::string(name))); // int
} catch(std::invalid_argument err) {
return variables.at(std::string(name)); //std::string
}
}
This function access a global map
Anonymous
hi all
Anonymous
anyone know to solve strings of mathematical expression into an integra
Anonymous
like(179-80) in array to display 99 in the output
Anonymous
{"18-151", "1*130", "71+59", example of the string
Hima
Anonymous
yes
Anonymous
it has +,-,*,/
Anonymous
but in single operators
Hima
yes
Then use their ASCII values to extract the numbers and perform your operation based on the operator.
Anonymous
how bro?
Hima
how bro?
num=0;k=0;
while(str[i]>=48 && str[i]<=57)
num=num+(str[i]-'0')*pow(10,k++);
Hima
Anonymous 🇪🇦
coal
coal
template<class T> and then use T as return type for the method
coal
otherwise, i cant think of a way to do such
coal
btw if you're in C then i think you're out of luck
coal
maybe in C you could do a char* and then return a "pointer," which would be the integer you wish to return, and then cast it
coal
or a pointer to a newly allocated string, as required
coal
Anonymous 🇪🇦
But templates don't work for return types right?
coal
they do
coal
"T functionname(T param)" gets compiled to:
using mytemplate<int>:
int functionname (int param) {}
using mytemplate<std::string>:
std::string functionname(std::string param) {}
Anonymous 🇪🇦
Well, but i need to use same argument
coal
then don't specify T for the param
coal
lol
Anonymous 🇪🇦
And how the compiler knows which function to call?
coal
¯\_(ツ)_/¯
coal
figure that out, you're the one with the issue
coal
but with templates you're set
Anonymous 🇪🇦
Templates do not work '--
coal
also, returning two types from the same function sounds like a bad design
coal
Templates do not work '--
https://stackoverflow.com/questions/52380498/c-function-that-returns-string-float-or-int
here googled it for you
coal
you need an overload
coal
for example use T and a reference to the variable
coal
T mymethod(T &variable)
Anonymous 🇪🇦
The arguments are not the same in the calls
coal
Anonymous
coal
not both
Anonymous
its one or other
or maybe templates with dcltype(auto) as return type?
coal
yeah i suggested templates, the OP is currently trying to implement them
coal
what
coal
you're trying to do a function that returns a different type every time
Anonymous 🇪🇦
error: 'auto' in return type deduced as 'std::basic_string<char>' here but deduced as 'int' in earlier return statement
coal
you're trying to reassign a different type to an auto
coal
the type of a variable initialized as auto must be the same during its lifetime
coal
meaning, you need two variables for different return types
coal
or you need to use std::variant
coal
Anonymous 🇪🇦
coal
you want to use a typed language without enforcing types
coal
you're technically doing a int myvar = "hello world"
Anonymous 🇪🇦
It's not about variables, it's about function redefinition
coal
at this point im absolutely lost
coal
i speak fluent spanish if you want i can help you in dms
Suka
but in single operators
perhaps you can start from this? cmiiw
int main(void)
{
char *arg[]={"1+1","2-1"};
int num1=0;
int num2=0;
char opr=0;
sscanf(arg[0], "%d%c%d", &num1,&opr,&num2);
printf("num1=%d\tnum2=%d\toperation=%c\n",num1,num2,opr);
return 0;
}