« first day (2836 days earlier)      last day (13 days later) » 

5:43 AM
I'm trying to debug some code. When compiled with g++ it runs into an infinite loop with no errors (even when using fsanitize). However with Visual Studios it gives the error message "Debug Assertion Failed!" and "Expression: cannot dereference end list iterator".
 
I don't think gcc has those DEBUG_ITERATOR_LEVEL things that VS has
but yeah, dereferencing an end() iterator would do the trick as far as undefined behavior is concerned
 
Why would Visual Studio produce a runtime error but not g++? It would seem an assertion is failing from inside one of the used libraries. Does running the debugger in VS enable assertion within the libraries?
How do I find which line of source code is messing things up?
 
if you have an assertion firing then using the debugger to set a breakpoint on assert should do the trick
then look up the callstack
 
@PeterT how do you set a break point in the std::list library?
 
just set a breakpoint on the names "assert' and "_assert". At least that's what I would do
 
5:50 AM
Let me rephrase, how do I open the library?
 
the headers that include the implementation are included with your compiler
but if you just set the breakpoint and run the program then you'll find the file, otherwise you can go looking to where they're stored and open them yourself
the container part of the STL is almost fully implemented in headers, there's no runtime library that you need to open for that if that's what you're lookin for
 
Ok found it
Say you have an iterator that points after the end e.g. std::vector<int> vec = {1,2,3};
auto itr = vec.end();
auto itr2 = std::next(itr);
auto itr3 = std::next(itr2);
Is any of this UB? Or no because nothing is being done with it and just having an invalid address isn't an issue?
Are itr, itr2 and itr3 all at the same location?
 
 
4 hours later…
10:14 AM
@Mgetz it doesn't roll up! if I have a struct of size 5
struct A
{
char a,b,c,d,e;
};
struct B
{
A a;
char b;
}
the size of B is 6!
it rolls up based on the biggest alignment in class A and B, this is what i noticed!
so if class A is 1 alignment of size 5 and class B has maximum alignment of 2 , class B will be aligned with 2 even if class A is of size of 5
if class A is 2 aligned and class B has maximum of 1 aligned variables (other than the struct A of course), then class B will also be 2 aligned
 
 
2 hours later…
12:31 PM
@ma1169 not a safe assumption, it's platform dependent
 
@Mgetz omg, so i have to learn how each platform i am using handle struct calculation -_-
 
it only really matters when designing a serialization format
 
@ma1169 just curious why do you care? There are valid reasons to, but generally most people are looking to save memory by understanding
 
and then you would pragma(pack, 1) it anyway
 
exactly or use a binary writer that gives you byte level control along with endianness control
 
12:41 PM
I had an interview at game company and I was asked to calculate the size of struct, and memory optimization questions, SIMD etc
 
@ma1169 rule of thumb is a struct is aligned to it's most aligned member, the memory is determined by the alignment and padding of the submembers combined
but it's wholly platform dependent
 
Thanks
 

« first day (2836 days earlier)      last day (13 days later) »