Anonymous
Could anyone point me to a resource in order to see the new features of each C++ standard above c++11?
The link mentioned above also has a link to the proposal papers which is a wealth of information. You don't have to read any book to understand the new features. The proposal papers are an encyclopaedia by themself. For some stuff like modules, coroutines, concepts and ranges, you will obviously have to refer to other sources but.
Anonymous
But the problem with them is that they are somewhat nerdy & formal
Yeah when you are talking about big features like modules and stuff. But for something as simple as 'deducing this' and so on, i found the proposals and the rationale behind them more illuminating than any blog post. You can ignore the parts where they suggest changes to the standard wording.
Danya🔥
I'd like to share a very nice channel https://youtube.com/@CoffeeBeforeArch I've not checked his C++ videos but I assume that they are good
Danya🔥
This is not an ad of any sort
Anonymous
Is there any regulations, declaring the only right way of writing code in C++? Like how should I declare a function: like this -> int main() {} or like this -> int main() { } ?
Anonymous
And when it comes to declaring a pointer: int* a = b; Or int *a = b; ?
Anonymous
Also, I would like to ask which case is more preferable for C++: camelCase or snake_case. On the internet I saw people use both of them. Same with 2 previous questions, every programmer has his own mind about writing design.
Anonymous
Unfortunatelly not ☹
So my style is completely up to me?
Ziky
So my style is completely up to me?
Usuakky up to your company or opensource project.
Anonymous
Thank you guys!
klimi
See clang for some types
klimi
They have quite nice docs for clang format
Danya🔥
Clang in particular and LLVM in general have very bad user documentation except for few gems probably
Adaita (MedTech | Healthcare)
And when it comes to declaring a pointer: int* a = b; Or int *a = b; ?
You could use clang format integrated with many IDEs these days. Particularly on pointer declarations best practice is to put the asteric just before the variables rather than just after the types. Imagine declaring multiple pointers in a single line: int *p, *q, *r; Though it is not a good practice to declare multiple variables in a single line.
Michel
Could anyone mentor me in this exercise at exercism.com? I'm getting an undefined reference to error that I don't understand.
Anonymous
Hi
Adaita (MedTech | Healthcare)
I always put the pointer on the type side, for it is an alteration of the type
int* p, q, r; This statement will make only p a pointer not q and r. As long as you are declaring a single variable per line, then no issues.
klimi
Clang in particular and LLVM in general have very bad user documentation except for few gems probably
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#basedonstyle It has the styles listed even with the urls, so... I would say it's good enough
Chat Boss
Артем sent a huge message, it has been re-uploaded as a file Hello guys, I have a question If I have file1.h void* a(void); file1.c static int b(void) { r..
Chat Boss
Leovan sent a huge message, it has been re-uploaded as a file Hi guys, why some compilers don't want to compile this: main.cpp #include "func.h" int main() ..
Anonymous
Артем sent a huge message, it has been re-uploaded as a file Hello guys, I have a question If I have file1.h void* a(void); file1.c static int b(void) { r..
You cannot cast a function pointer to void*. A pointer to some data may be different from pointer to functions in some architectures. There are architectures were a function pointer is twice the size of a data pointer. So this is illegal in C. Posix systems allow conversions between void* and function pointers. On such a system, you may have to change file2.c to something like this: #include <stdio.h> #include "file1.h" int main(){ int (*func)(void) = a(); printf("%d\n", func()); }
Anonymous
Leovan sent a huge message, it has been re-uploaded as a file Hi guys, why some compilers don't want to compile this: main.cpp #include "func.h" int main() ..
You have not included iostream in func.h. You must include iostream in any file that includes func.h and this include must happen before you include func.h unless you use forward declarations. Ideally you must move the function definition to a cpp file so that files that include func.h don't have an indirect dependency on iostream
Ludovic 'Archivist'
Ludovic 'Archivist'
Readability is more important than conciseness
Anonymous
Yes, and you should declare those each on a different line and with clear names
I agree with declaring only one variable on a line. But I usually use int *p to reflect the fact that p when dereferenced returns an int. This is clearer to me.
Anonymous
Ludovic 'Archivist'
Lol. You must switch to Rust then
Sadly, I deal with a lot of self referential data structures
Ludovic 'Archivist'
Time to refactor
Sadly, no, refactoring in that case would mean making things far slower which is another problem
Anonymous
Ziky
I am looking forward when I grow up and will be able to naturally find right balance between quick solution and overengineered one 😁
Ludovic 'Archivist'
Then just make a nice, safe wrapper
How do you wrap a self referencial data structure without the Rust borrow system killing itself at runtime exactly?
Ludovic 'Archivist'
Use a Box smart pointer.
I forgot to write efficiently
AlanCcE
It's not too much but i just wanna share that i write 60 lines of C code and i compiled it without any errors, i'm feeling powerful 🤯
Ludovic 'Archivist'
Well, in the end I just end up writing my own programming language
Danya🔥
Enabling clang-tidy in a codebase that exists several years is such a pain in the ass
Danya🔥
Especially with CI that runs 5 hours
Danya🔥
I use GCC btw, clang has any benefit?
Google what clang-tidy is
Anonymous
I use GCC btw, clang has any benefit?
clang-tidy is not tied to clang btw.
Ziky
Enabling clang-tidy in a codebase that exists several years is such a pain in the ass
we have script to filter out complains only on your changes
Danya🔥
we have script to filter out complains only on your changes
Well To enable clang-tidy you need to fix all the issues in the code anyways
Ludovic 'Archivist'
I use GCC btw, clang has any benefit?
Clang has better tooling in some parts, GCC has a better debugger for some cases, Clang is taking a safer approach on the standard, GCC is going for performance above else (and sometimes fails miserably), they give error messages differently I recommend to use both if possible, if just for the benefit of easier to find/use error messages
AlanCcE
Google what clang-tidy is
Wow, this tool seems interesting, im going to add it to my arsenal
Danya🔥
Wow, this tool seems interesting, im going to add it to my arsenal
https://github.com/cpp-best-practices/cppbestpractices
AlanCcE
https://github.com/cpp-best-practices/cppbestpractices
I'm more into C than C++. u think this list should be useful anyway?
Anonymous
https://github.com/cpp-best-practices/cppbestpractices
These links have already been mentioned in the Resources section.
Anonymous
C++ Guidelines - This site lists guidelines for C++ Programmers. Both Bjarne Stroustrup and Herb Sutter monitor the guidelines here to ensure they reflect the current standards on best programming practices. CPP Best Practices - This site is maintained by Jason Turner (one of the cppcast podcast host) and perfectly compliments the site above.
布丁
How do you wrap a self referencial data structure without the Rust borrow system killing itself at runtime exactly?
Write some unsafe code inside the implementation while exposing only the safe interfaces
Anonymous
Write some unsafe code inside the implementation while exposing only the safe interfaces
You don't need unsafe for this. You can use Rc (Arc if it is multithreaded code) to enable self referential data structures. The borrow checker will be perfectly happy with it
Anonymous
He wants extreme performance so…
Rc performance is good. Arc might be slow because of the atomic count. Rust like C++ works on zero cost abstraction. If you used pointers and managed the memory manually, you will end up doing something similar to what Rc does
Anonymous
I don’t think a linked list needs reference counting?
Not a linked list. I am talking about a data structure where a node may end up referencing itself or the same node can be referenced by two different nodes. Think of it like a branched linked list. My point is that people think Rust can't support things like this when it clearly can and you don't even have to delve into unsafe dark corners of the language for it.
布丁
Rc/Arc for linked lists only exists at LeetCode
Anonymous
The most common case I can think of is doubly linked list or tree etc., and that is usually how Rust guys do
Well there are a lot of graph data structures like adjacency Matrix which I can think of that are not exactly a doubly linked list.
Engineer
why so?
You will be able to compile the kernel learning from an existing code base. The more code you read the earlier the better you become over time
Engineer
why so?
You have access to an ecosystem that Microsoft has not touched. Why do you think they did WSL?
mito
#include <iostream> int main(){ int a; std::cout << "Hello"; std::cin >> a; return 0; } Does std::cin make the buffer of the std::cout above it flush ?
mito
#include <iostream> int main(){ int a; std::cout << "Hello"; std::cin >> a; return 0; } Does std::cin make the buffer of the std::cout above it flush ?
Nvm, I found the answer on cppreference. "Once std::cin is constructed, std::cin.tie() returns &std::cout, and likewise, std::wcin.tie() returns &std::wcout. This means that any formatted input operation on std::cin forces a call to std::cout.flush() if any characters are pending for output."
Long
hi everyone
Long
I have a question
Long
how to simulation binary search tree on graphic c++