Pavel
When should I typedef structs in C?
Mar!o
It is a common practice to typedef structs in C to avoid writing struct, enum, union all over the place...
Pavel
For example, in ffmpeg (libavutil, some structs are typedef'd, while some aren't)
Pavel
For example, in ffmpeg (libavutil, some structs are typedef'd, while some aren't)
Linux kernel coding style forbids using typedef for structures
Mar!o
Yeah I also don`t like to do it for that
V01D
For example, in ffmpeg (libavutil, some structs are typedef'd, while some aren't)
Here is some sample code I wrote to describe the difference a little more clearer: https://pastebin.com/Ln4qxYg9
Mar!o
At least how it is there. Come on just add a second variable with the correct type to make it less confusing for beginners.
Mar!o
Now it looks like the second one would be static or global
Mar!o
Also I the difference is not only at initialization, it is every time you mention the type. Without a typedef: struct some var; with typedef: some var;
Mar!o
But it really populates the global namespace if you typedef anonymous types that's why many do: typedef my_struct { ... } my_struct;
Anonymous
Hi, I'm new of language C, have one tutorial free good for begginers?
Anonymous
/get cbook
Anonymous
C++ is like a high level version of C
No, it's not C++ is not C with classes
Anonymous
2 nested loops -> O(n^2) 3 nested loops -> O(n^3)
It is very depend at the scenario, it might be O(n) or O(log(n)) or O(n^10) or something else
Anonymous
How can you in c++ name a text file name after a string?
Anonymous
Wat
String.txt but it doesnt work with string + ".txt"
Anonymous
String.txt but it doesnt work with string + ".txt"
I don't understand what you're talking about
Anonymous
I don't understand what you're talking about
Read a string as a text file name with fstream
Anonymous
Read a string as a text file name with fstream
std::ifstream file { "string.txt" }; std::string str; file >> str;
Anonymous
std::ifstream file { "string.txt" }; std::string str; file >> str;
No as the name of the textfile, if you use double quotes it is no string anymore?
Anonymous
I don't understand you
I will ask the question again with code when I have my computer
Pavel
No as the name of the textfile, if you use double quotes it is no string anymore?
#include <fstream> #include <iostream> int main() { std::string str; std::cin >> str; std::ofstream file{str + ".txt"}; file << "Hello, world!" << std::endl; }
Pavel
That works
Anonymous
what does double do in c ,I googled it but dint understand.
Alex
this is floating double precision type
Anonymous
what does double do in c ,I googled it but dint understand.
It's a type for floating-point numbers
Anonymous
my frnd said it takes int and float
Anonymous
is that wrong
Alex
what do you mean "it takes"?
Anonymous
my frnd said it takes int and float
It doesn't make sense
Pavel
"* Only English language is allowed, if you speak shitty English or don't understand anything in English YOU WILL BE BANNED."
Anonymous
sorry sir I got it ,thank you
Pavel
Thanks
BTW, what did you try?
Anonymous
BTW, what did you try?
I did something like this but didnt work. Also tried with .c_str() but after your answer I think I know the problem
Pavel
Ah, yes, I see. C-style string is a sequence of chars that ends with '\0'.
Pavel
You will get weird result if you add char* to char*
Anonymous
include <stdio.h> double a(double x,double y) { double sum; sum=x+y; return sum/2; } main() { double j,h; scanf("%g%g",&j,&h); printf("%g",a(j,h)); }
Anonymous
'j' and 'h' values which I entered not copied to x and y to get returned
Anonymous
hm, again iam trying,sorry I want to enter j and h which should be copied to x and y to get average of j and h
Anonymous
Iam getting error
Anonymous
How did you understand that the values are not copied?
Anonymous
Iam getting error
What error???
Anonymous
Iam asking whether the program is wrong
Anonymous
Screenshot (12-Aug-2020 2:16:19 PM)
Anonymous
Anonymous
lg instead of g
Ok, how simple is that, thank you
Anonymous
/warn
Anonymous
what is Pming
Nameful
what is Pming
Private Message:ing
Anonymous
sorry I got it I never do again
Balaji
👋
su
hi all, who interested in vscode .devcontainer development with cmake and bezel, welcome on my twitch channel, i need help on bezel config, nick the same
V01D
Seems like typedef can assign a new name to a data type. typedef unsigned char byte
Flash
yeah even a function type
V01D
I just learned typedef wrong, thats all.
Vlad
I swear it gets people every time)))
Flash
I just learned typedef wrong, thats all.
so what did you think about it?
V01D
I thought typedef shortens the initialization of structs and unions.
V01D
Thats completely wrong
The post above is the code I wrote, if you want to look at it.
labyrinth
is there any particular reason that the unordered_map simply use collision chaining to deal with hash collision, without strategies of like transforming the linked list to RB tree or copy the data to a new space ruled under a new hash function / memory ?
Kenny
look into c++ reference
Anonymous
yep)
In which office? Moscow? USA? Israel?
Noble Friend
Hi here, need some help please. Here is a segment of code, i want it to run while waiting for user to press a key but it loops just once and stops. Any idea on what i should do? please (I want it to keep printing '1' till the key is entered. #include <ncurses.h> int main (void){ char press; while(press != 'q'){ printf("1"); press = getch(); } printf("You pressed 'q'"); } Thank you
Dima
you need to update 'press', because it’s not updating as I see