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
Shvmtz
Try nm .. nm -S maybe it will work
I haven't used nm tool before :(
Shvmtz
$ nm -S a.out 0000000000003e00 d _DYNAMIC 0000000000003fc0 d _GLOBAL_OFFSET_TABLE_ 0000000000002000 0000000000000004 R _IO_stdin_used w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable 000000000000212c r __FRAME_END__ 0000000000002004 r __GNU_EH_FRAME_HDR 0000000000004010 D __TMC_END__ 0000000000004010 B __bss_start w __cxa_finalize@@GLIBC_2.2.5 0000000000004000 D __data_start 00000000000010e0 t __do_global_dtors_aux 0000000000003df8 d __do_global_dtors_aux_fini_array_entry 0000000000004008 D __dso_handle 0000000000003df0 d __frame_dummy_init_array_entry w __gmon_start__ 0000000000003df8 d __init_array_end 0000000000003df0 d __init_array_start 00000000000011b0 0000000000000005 T __libc_csu_fini 0000000000001140 0000000000000065 T __libc_csu_init U __libc_start_main@@GLIBC_2.2.5 0000000000004010 D _edata 0000000000004018 B _end 00000000000011b8 T _fini 0000000000001000 t _init 0000000000001040 000000000000002f T _start 0000000000004010 0000000000000001 b completed.8060 0000000000004000 W data_start 0000000000001070 t deregister_tm_clones 0000000000001120 t frame_dummy 0000000000001129 000000000000000f T main 00000000000010a0 t register_tm_clones $ nm -S a.out | grep bss 0000000000004010 B __bss_start
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
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?
Anonymous 🇪🇦
{"18-151", "1*130", "71+59", example of the string
- loop the array. - parse the left, operation, right using a loop over the string or a regexp - cast left and right to int - make some conditionals checking which operator is defined - return the result
Hima
how bro?
num=0;k=0; while(str[i]>=48 && str[i]<=57) num=num+(str[i]-'0')*pow(10,k++);
Anonymous 🇪🇦
Or you can return a pair , first value for int and second for string
i need an int or a string as return value, not both at same time
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
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
look into tuple
its one or other
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
Anonymous 🇪🇦
or maybe templates with dcltype(auto) as return type?
I already tryied, but can't return one type if the function returned another before
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
Anonymous 🇪🇦
the type of a variable initialized as auto must be the same during its lifetime
Thank's for telling me after i already tryied and pasted the error message.
Anonymous
yeah i suggested templates, the OP is currently trying to implement them
And really, I believe a function should do exactly one thing. If he finds himself in situation needing to return multiple types from a function then they have design issues
coal
That makes no sense
it makes absolute sense
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; }