Sola
In this group, who are the experts or teachers of c programming, whoever they are, raise your hand or type yes and send it. I am creating a group .. I add to it .. I need help for the exam ..
Very laughable. 😃 Is this some sort of joke OR what? Well you can only get help from people who are just learning like you. Working Developers wont have time for such frivolities
Anonymous
Hi please I want to learn c++ can anyone give me tips
Anonymous
Please I just want to start
Anonymous
Please I just want to start
Read C++ Primer by Stanley Lippman.
Anonymous
Please I just want to start
g++ and ubuntu, good start
Anonymous
why some libs has implemented as *.hpp files, not a *.h and *.cpp like classic c++
Anonymous
why some libs has implemented as *.hpp files, not a *.h and *.cpp like classic c++
.hpp is just a header file. People use .hpp as an extension mostly to distinguish them from C header files which are <name>.h files. It is better to use .hpp extension for C++ header files (unless you want the header file to be used with C code as well in which case you should use the .h extension) and a majority of modern C++ code does that.
Anonymous
https://github.com/Snowapril/String-Obfuscator-In-Compile-Time
Anonymous
see this code
Anonymous
Anonymous
this is an example of metaprograming. I think the *.hpp using if *.cpp is not needs and the functions or classes are not implemented at all
Anonymous
this is an example of metaprograming. I think the *.hpp using if *.cpp is not needs and the functions or classes are not implemented at all
No that is not the reason for using .hpp extension. This is just a header only C++ library. The reason why they use .hpp extension for header only libraries is to make it explicit that it is a C++ only header. It cant be used with C code.
Anonymous
ok *.h = *.hpp at c++. But where is *.cpp ? Is it really not needed if library used only macroses and only templates?
Anonymous
ok *.h = *.hpp at c++. But where is *.cpp ? Is it really not needed if library used only macroses and only templates?
Header only libraries are used only when the libraries are small and also when there is template metaprogramming involved. Header only libraries have the advantage of making the build process easier. You dont need to link your libraries in. Just including the header file is good enough. If bigger libraries are implemented as header only libraries it will lead to problems like hugely increased translation unit and object file sizes (in other words code bloat) and will also increase the build time of your code. If you make changes to a header only library you will have to recompile all the source files that include the header files. In a normal library (with both .hpp and .cpp files), you will need to build the client code only if the header file changes. Otherwise, just linking again is good enough. The client code does not need to be recompiled. So, only small libraries like the individual units in Boost and others are implemented as header only libraries. Bigger projects need to separate the interfaces and the implementation.
@𝑺𝒐𝒃𝒌𝒂
why some libs has implemented as *.hpp files, not a *.h and *.cpp like classic c++
cpp is the recommended extension for C++ as far as I know. Some people even recommend using .hpp for C++ headers, just to differentiate from C. It's just a preference, compiler doesn't care what you do
Anonymous
thanks for the answer
Anonymous
Yes 💞
Anonymous
hai
Anonymous
eg this CANNOT be in a header only file class HEADER_ONLY_MATH { // WRONG, this will produce duplicate definition HEADER_ONLY_MATH::sum void sum(int a, int b) { return a + b; } // CORRECT, this will NOT produce duplicate definition due to template instantiation template <typename T> void sum_(T a, T b) { return a + b; } } // CORRECT, this will NOT produce duplicate definition due to template instantiation template <typename T> class HEADER_ONLY_MATH_TEMPLATE { void sum(T a, T b) { return a + b; } }
Anonymous
tho i am not sure if using TEMPLATE<int> in multiple translation units will produce multiple definitions of class TEMPLATE since they both instantiate to the exact same type
Anonymous
Any one tell us how to work reflection in java
it is also worth noting that it is best to cache your reflection results as much as possible to avoid additional overhead of looking up the methods and fields and so on mostly you need to cache Method and Field, and maybe some other stuff i cannot remember at the moment think of it as equivilant of lazy linking in the linker where Reflection can be akin to the dynamic linker classes, methods, fields and so on can be akin to the objects and symbols that the linker needs to map and link together (the linker does this ONCE, and ONLY ONCE unless the library is unloaded and loaded again, HOWEVER it MIGHT be smart enough to cache this map for a period of time instead of just deleting the map when ever the library gets unloaded caching the map avoids work when quickly unloading and reloading the same library, in which the map will be deleted after x amount of time has passed in order to save memory) but in java, classes ONLY get unloaded under very specific cases so it is always a good idea to cache your results and then recache them if your class gets reloaded by using static initializers
Anonymous
:)
Shishir
https://github.com/oz123/awesome-c
Anonymous
Anonymous
tho i am not sure if using TEMPLATE<int> in multiple translation units will produce multiple definitions of class TEMPLATE since they both instantiate to the exact same type
Depends on how your class template is defined. Class template instantiations in header only libraries should not violate ODR rules.
Anonymous
Hello, good morning. Does anyone know c ++ language? I have a few coding questions
Golden Age Of
Hello, good morning. Does anyone know c ++ language? I have a few coding questions
Group is called C/C++ programming, so ,I guess yes, someone should know
klimi
Hello, good morning. Does anyone know c ++ language? I have a few coding questions
Dont ask to ask, this is c and c++ group, what do you think?
Anonymous
I am a student and I have a C ++ exam. Can anyone help me?
Golden Age Of
I am a student and I have a C ++ exam. Can anyone help me?
Just ask your question, someone will help
Anonymous
Just ask your question, someone will help
The exam starts in another hour
klimi
I am a student and I have a C ++ exam. Can anyone help me?
We dont promote cheating on exams... Come back after exam is over if you have any doubts
klimi
The exam starts in another hour
Then its okay to ask before it starts :)
Anonymous
Hi
klimi
Hi
nohello.com
Anonymous
oof invalid link
Anonymous
Depends on how your class template is defined. Class template instantiations in header only libraries should not violate ODR rules.
Hmm even if, say template <typename T> class X { T add(T a, T b) { return a + b; } } A.cpp X<int> x; B.cpp X<int> X;
Vlad
C++ has static storage class of global variables by default
Vlad
If you were to put it as extern into the header and then define it twice. Then yeah big oof
Anonymous
move template to *.hpp and reinclude at *.cpp files
Anonymous
Hmm even if, say template <typename T> class X { T add(T a, T b) { return a + b; } } A.cpp X<int> x; B.cpp X<int> X;
This doesnt violate ODR. The method "add" is inline here and the linker folds multiple such instantiations into a single one.
Anonymous
C++ has static storage class of global variables by default
You didnt understand his question. One variable is named x and another variable is named X. They are different. And if they were both named x or X, it is indeed an ODR violation. So you are wrong on that part as well.
Anonymous
#pragma once
The question that he asked has got nothing to do with your answer.
Anonymous
🆗
Anshul
In c++ if I create an array of size 10 and I want to access 10th index then why compiler gives no error. Int a(10); Cout<<a(10)
Anonymous
int a[10]; a[9] = 12; cout << a[9];
Dumb
You are accessing something that neither exists
Anshul
You are accessing something that neither exists
I know but my question is compiler doesn't stop me from doing so.
Anonymous
you see an error at runtime
Anonymous
In c++ if I create an array of size 10 and I want to access 10th index then why compiler gives no error. Int a(10); Cout<<a(10)
Because the standards dont require them to. But most compilers do warn about it. And the reason why the standards dont require a diagnostic is because it is impossible for the compilers to determine all contexts where an out of bounds indexing happens. So the standards cant be restrictive and say that this diagnostic is required only in the cases where a constexpr index is used.
Anshul
I was trying to implement segmented sieve but when I compile (on codechef ide)I get an error SIGSEV. And I can't find the reason why?? Can I share the whole code here
Anonymous
What is constexpr idx. And what is sigsev?
constexpr in C++ is something like Integral Constant Expression (ICE) in C. Search for constexpr and consteval on Google
Pavel
In c++ if I create an array of size 10 and I want to access 10th index then why compiler gives no error. Int a(10); Cout<<a(10)
This is runtime information the compiler doesn't check for that, you can use a.at(10); then it will throw an exception
Anonymous
I was trying to implement segmented sieve but when I compile (on codechef ide)I get an error SIGSEV. And I can't find the reason why?? Can I share the whole code here
Debug it. It usually happens when you access memory that you are not supposed to. People here may not do the debugging for you.
@𝑺𝒐𝒃𝒌𝒂
Anshul
Debug it. It usually happens when you access memory that you are not supposed to. People here may not do the debugging for you.
As you said compiler doesn't throw an error even if I try to access out of bounds of array then why am I getting SIGSEV
Anonymous
As you said compiler doesn't throw an error even if I try to access out of bounds of array then why am I getting SIGSEV
Because C++ compilers are not required to determine if your program can access memory it is not supposed to. And so if you do so, the compiler happily generates the machine code that does so. But your OS is an asshole and wouldnt let you off so easily.
Pavel
As you said compiler doesn't throw an error even if I try to access out of bounds of array then why am I getting SIGSEV
When you say "compiler" do you mean that it should happen on compile time?
Pavel
Yea
The C++ compilers usually don't do checks like this. You can try to find some linter/static analyzer that does such checks and run them on your code. But that's not very common case when you specify the size and index known at compile time, usually at least the index is dynamic, then even the linters won't be able to help.
Anshul
Thanks 👍
Anshul
I still can't find why am I getting a seg fault. I have tried to debug it. Can anyone help
Pavel
I still can't find why am I getting a seg fault. I have tried to debug it. Can anyone help
You get it because it's UB https://stackoverflow.com/questions/1239938/accessing-an-array-out-of-bounds-gives-no-error-why