« first day (826 days earlier)      last day (2033 days later) » 

1:59 AM
Is it good enough to use this clang.llvm.org/docs/LeakSanitizer.html to detect memory leak? For example, I write a class and try to see if I handle the dynamically allocated correctly.
I am using g++ Ubuntu.
 
 
8 hours later…
nwp
9:48 AM
@Rick You should avoid memory leaks by construction, which means by making std::vector or std::unique_ptr or some other memory management class manage your memory. If you absolutely must write your own memory management class then LSan is a decent check for making sure you have no leaks. If you combine that with excessive tests you should be good.
 
10:30 AM
Ok thank you. I am doing some data structure implementation exercises. So I think I have to manage the memory on my own.
 
 
2 hours later…
Max
12:25 PM
Hi there,
I'm having issues to figure out how to extract all the informations that I need to use a class in c++. I was browsing SO and stumpled upon this question: https://stackoverflow.com/questions/236129/how-do-i-iterate-over-the-words-of-a-string
In the question the OP posts some code and I can't figure out why the code works as it does. More specifically I can't understand how the overloaded operator>> works. Why does the assignment 'iss>>subs;' assign just one word at each iteration and how can I find this information on http://www.cplusplus.com/reference/istream/istream/operator%3E%3E/ or on a
 
iss>>subs; translates to iss.operator >>(subs);which is just a normal function call. That function takes a reference to a variable which it can write to.
 
Max
yes, i got that. But I don't understand how that function works. On the link that I posted it says that the function is not defined for string-arguments. So which of the functions is called? and Also I don't understand, why it only assigns one word per iteration. The link doesn't say a word about this behaviour as far as I see. Or am I reading it wrong?
 
I don't recommend cplusplus.com, cppreference is usually less misleading
This is the equivalent page for operator<<. It also doesn't list these overloads in that page, but it links to other operator<< overloads, because they're defined in different header files en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt
(operator>>(std::ostream&, std::string&) is a non-member operator overload)
 
12:40 PM
ah right so iss>>subs; actually translates to operator >>(iss, subs);
 
Max
@milleniumbug thanks a lot. Also for the recommendation to use cppreference. When you google things, you usually find both and so far I considered cpluscplus.com prettier and have been using it more. But I will switch to cppreference now.
 
back when I was learning C++, I initially dismissed cppreference as "needlessly wordy" and "TL;DR", but in time I've learned to appreciate the precise wording.
also, it used to be that cplusplus was outright wrong in places
supposedly it's better now, but the main problem is that cppreference is a wiki, and cplusplus is not
so cplusplus is going to get slower updates
 
Max
I see. I agree that more precise is usually better. Especially coming from Matlab where everything is documented in an incredibly detailed and precise fashion.
 
I've looked at cplusplus.com now, and it seems it only has C++11 related info, but in the meantime C++14 and C++17 have been released and it doesn't seem to provide updated information there
So it seems I should continue telling people to not use cplusplus.com
 
Max
Probably you should :D
 
 
2 hours later…
3:22 PM
Hi. Suppose that I have:
void f(CLASS &c){
....
}
What's the easiest way to make it template for both xvalues and glvalues?
 
nwp
Maybe forget about templates and add an overload void f(CLASS &&c).
Which simply calls f(c);.
Although that would arguably be bug-hiding. Modifying a temporary makes no sense.
 
3:47 PM
I do not need to preserve information which is written to xvalue and I cannot force every code author to not write anything to object what is not of any use to me.
I would prefer template to have just one definition. Is there a way?
 
hi i have a question
\\?\Volume{4c1b02c1-d990-11dc-99ae-806e6f6e6963}\
i have this volume name
i get from runnig a function
i want to know that is the meaning of the 4c1b02c1-d990-11dc-99ae-806e6f6e6963 part
is it the label converted to hexadecimal?
 
nwp
@EuriPinhollow I don't see a way besides using a regular template and then enable_if to stop making it behave like a template. A better approach might be to write a wrapper that captures temporaries and non-temporaries by reference.
@jeyejow Probably a UUID.
 
but when i convert it from hex to text i get something like this:
LÁِܙ®€nonic
i tried with UTF8 but i get error
in a online converter
 
It's not a text and you are not achieving anything by trying to convert it to text.
 
ah, i though it was the name of the drive converted to hex
 
nwp
4:00 PM
@nwp Actually capturing temporaries by reference in a wrapper sounds like a terrible idea.
 
one more question, i have a int mian like this that i saw:
void __cdecl wmain(void)
what does _cdecl and wmain mean?
wmain i think is wide main, but i dontt know how it changes the code (if it changes annything)
 
nwp
@jeyejow You can type either one into your browser's address bar and find detailed documentation about what they are and do.
 
oh ok
"because it requires each function call to include stack cleanup code" what does this mean?
the code cleans itself?
if i malloc i dont need to free?
 
nwp
No, that's not what it means.
Look up "calling convention".
It describes how to pass arguments, how to pass return values and who need to modify the stack pointer in what way.
Unless you are a compiler you don't care.
 
but why do they use it?
should i use it?
 
nwp
4:08 PM
Because windows needs to call wmain in order to start your program, so windows has to know how to do that. They do that by defining that wmain must use __cdecl so they know how to call it.
 
why not just void main() ?
 
nwp
If you don't use it the compiler will probably chose some default calling convention which may or may not be __cdecl.
@jeyejow You can use that. Windows just provides an additional function to allow passing wchar_ts instead of chars because that makes sense on windows.
 
ohhh ok, i get it
so this means that i call function with wchar_t insted of char ?
else i wouldnt be able to call them
?
 
nwp
You are not allowed to call main either way. The operating system does.
Or whoever else is there.
 
thts not what i mean, if i have a main, i cant call function from the main that takewchar_t , correct?
but if i have a wmain, i can?
 
nwp
4:12 PM
No, not correct. You can call whatever functions you want.
 
so its only for the arguments i pass to wmain?
for it to use wide chars?
 
nwp
The difference is that when someone does yourprogram thefileöüß.txt that the argument either ends up using the system's codepage in your main as a char * or in utf-16 in your wmain as a wchar_t *.
That's all.
 
ohhhh ok
i get it now, thanks
so this would be pointless? void __cdecl wmain(void)
since i dont take argument??
 
nwp
Probably. The operating system has to know which function to call, main or wmain or WinMain or something else. Usually you pass a linker flag that does something to the executable so that windows knows.
If your system is set up to tell windows that it needs to call wmain you better have one.
 
hmmm ok
this is the code i saw it from:
 
4:21 PM
well if you want to get technical the entry point is to the C runtime that will initialize globals and such before going to call your main. Which main that gets called depends on your build setup.
 
he doesnt do that normally?
initiallize globals first?
 
that's the job of the C runtime
 
__cdecl ?
 
no that tells the compiler to construct the function to obey that particular calling convention
the C runtime is a bunch of libraries that will work to make sure the C spec is obeyed
it gets linked automatically
You can work without it but that is often more trouble than it's worth
 

« first day (826 days earlier)      last day (2033 days later) »