« first day (516 days earlier)      last day (2343 days later) » 

12:57 AM
@Yashas In most cases, it's still basically a mistake. You're still operating at a very low level of abstraction--how the data is represented. By strong preference, in most cases you'd have some type that represents the real meaning of the data instead.
 
1:11 AM
@JerryCoffin It's like there are only two categories of listeners in this case: one would say "I do not know" and the other would say "It is FUD". It's like telling int *i and int* i apart.
 
 
2 hours later…
3:08 AM
@EuriPinhollow I'd often tend to fall in a third category: if you care, you're probably paying attention to the wrong things (applies to both FUD and deciding where to add white-space to int*i;.
 
 
2 hours later…
4:51 AM
@JerryCoffin I have encoded information inside a 32 bit integer as individual bits and group of bits. I am using low level datatypes to allow the compiler to warn when data doesn't fit the size.
	uint32_t address;
	uint16_t flags;
	uint8_t argc;
	uint8_t type;
I combine flags, argc and type into one uint32_t many times
 
@Yashas They have things called bit fields for this sort of thing.
 
@JerryCoffin I can't use bit fields because the order in which the content is stored is implementation defined. I need to pass this encoded information to another program and I need to follow the correct order.
 
@Yashas You need to do that (only) for serialization.
 
That will incur extra overhead (convert the bit field to my order) but I think that is negligible. As of now I am cunningly making a copy of the object into a int32_t array using reinterpret cast which I think is a bad thing to do.
and I tell the compiler not to do any padding or other alignment stuff
this sounds messy
 
5:14 AM
Is it possible to put a struct inside a bitfield?
I have a 64bit bit field and 16 bits are used by flags. I want to access the flags by doing obj.flags and I also want to do obj.flags.some_flag (or something similar)
	struct {
		uint64_t address : 32;
		struct {
			uint16_t a : 1;
			uint16_t b : 1;
			uint16_t reserved : 14;
		}flags;
		uint64_t argc	 : 8;
		uint64_t type	 : 8;
	}info;
I don't know what's going to happen. The IDE isn't complaining anything about that.
it worked :O
 
 
3 hours later…
8:03 AM
I have exactly identical code (with identical purpose) in a constructor and a method, how can I make either one of them point to the other?
I don't want to keep two copies of the same code.
 
Can you make a function?
If you can't make a function you could probably use reflection but I doubt that's what you want
 
I can make a single copy and call that function in both the constructor and the method but that I think there is a nicer way to do it
 
Could you post some code? Maybe a simplified version?
Nevermind, I don't know anything better than just refactoring by using a function
 
8:55 AM
class test {
	public:
		test(int params[]) { //code }
		void assign(int params[]) { //code }
};
both those functions have exactly identical code
 
 
2 hours later…
nwp
10:35 AM
@Yashas Why not test::test(int params[]) { assign(params); }?
 
@nwp I think I need sleep
I am becoming more and more stupid
 
nwp
Sleeping sucks. Very unproductive. Someone should find a cure for it.
 
I have got just 5 hours of sleep in the last 2 days and I still feel like coding :D
 
11:19 AM
i want to delete an element in a vector. iterating over it in a loop, to find and erase the particular element, isnt the right approach. i get problems when i change the container while i iterating over it.
// Erase node from childNodes when found.
for (LMNode* child : childNodes)
{
// Id comparison.
if (*child == *node)
{
// Unset parent of child node.
child->parent = nullptr;

// Erase it.
this->childNodes.erase(&child);

// Recalculate the bounding volume.
calculateBoundingVolume();
}
}
 
nwp
11:33 AM
@FerencRozsa You need to use an iterator-based for-loop instead of a range-based loop for that.
erase returns the new next iterator. The old one becomes invalid because the element is gone now.
 
nwp
@FerencRozsa Almost. erase gives you the next element and then ++it goes 1 further, so you skip an element and you might go past the end. You have to put the ++it into the else.
 
what happends when the last element is deleted ? so erase gives next element -> skipped end ?
 
nwp
When eraseing the last element it returns v.end() and then the loop ends.
 
i define, that the particular element only exists one times in the container so maybe i can work with remove/erase idiom ?
 
nwp
12:00 PM
Sure. erase/remove also works with multiple elements.
 
what i understand is, that remove shifts all elements (that arent to be removed) in the front of the container. and i get back an iterator after that range which i can use for the erasing form there to the end of the container.
 
nwp
Yup. And erase can take 2 iterators instead of 1 and erase a whole range of elements.
 
12:19 PM
seems that QVector hasnt such a method like the standard remove
 
thats erase
 
nwp
std::remove should work on QVector too.
 
1:01 PM
i do it so:
while (it != childNodes.end())
{
// Id comparison.
if (**it == *node)
{
// Unset parent of child node.
(*it)->parent = nullptr;

// Erase it.
it = childNodes.erase(it);

// Recalculate the bounding volume.
calculateBoundingVolume();
}
else
{
++it;
}
}
thx nwp
 
1:45 PM
Spent last hour staring at the code which changes variable between two subsequent non-writing accesses to it and which is provably memory safe.
Deciding whether I should post it and ask a question or spend another six hours staring at it.
 
2:15 PM
Ok whatever. ideone.com/ZevwJY - here is the code which does a meaningless but well-defined calculation. It finds maximum element in an array and then redistributes it's value. There is a loop on lines 36-40 and additional check at line 41 which means that after new maximum value is found there should be three identical lines in the output. However, you can clearly see that three adjacent lines at the end of output are NOT identical.
After checking out all subscript and assignment operation four times I can say that it IS memory safe. What is causing this then?
 
I don't get it
which line in the output is wrong and what should be an expected one
 
 
1 hour later…
3:45 PM
There should be a block of
maxI 6
maxI 6
maxI 6
Somewhere at the end of output. Yet there is
`maxI 6
maxI 6
maxI 7`
@milleniumbug instead. These lines of output are produced by lines 39, 36 and 41 and there is no modifying statement between them.
 
@EuriPinhollow maxI on the line 36 and the maxI on the line 39 are different variables: shadowing is involved
 
ooooooooooooooooooooooooohhhhhhh
 
one is declared on the line 33 and the other is declared on the line 16
 
You can't imagine how thankful I am.
thanks thanks thanks thanks thanks thanks thanks thanks thanks
You saved me hours of doing nothing.
 
4:41 PM
is there a C++ alternative to assert?
 
4:53 PM
@Yashas Do you mean exception-wise? No such standard thing probably. I wrote and use this: coliru.stacked-crooked.com/a/6fb1678f5f66a592
 
cond1 && cond2 && cond3 vs cond1, cond2, cond3
The second one looks way better. I can use ur code, right? ty :P
 
Sure.
 
I don't have a main. If my code throws an exception, what happens to the host? I am not sure how an exception would propagate here.
I believe that the host program uses addresses to call the functions in my code. So?
 
If it try-catches, then it continues to live.
 
5:09 PM
It's written in C.
I just tested and it sent the entire process chain crashing.
 
Good question then lol.
You can substitute throw with exit.
 
I think exit doesn't do cleanup.
 
en.cppreference.com/w/cpp/utility/program/exit - it does. I am assuming that it is what you want to use because you asked about assert first.
 
There could be unwritten logs with non-empty buffers.
Ah, I have a poor memory.
 
Well it changed in C++11 so you probably don't.
However, do you want conditional assert (i.e. enabled only for debug builds) or not?
My solution has no condition inside.
 
5:15 PM
I added #ifdef NDEBUG around your code
 
5:59 PM
is this abuse of enums?
    enum
	{
		FUNCTION_TYPE_INVALID = 0x00,
		FUNCTION_TYPE_PUBLIC = 0x01,
		FUNCTION_TYPE_NATIVE = 0x02,
		FUNCTION_TYPE_DEFAULT = 0x04,
	};
when should I use anonymous enums and when should I use consts?
 
 
3 hours later…
9:12 PM
@Yashas When you need the features of one or the other. When in doubt, use enum class
Oh. Back in the day const static members in classes were annoying (they still are but much less so). That's where I think the idiom originated:
struct X {
    enum { id = 17 };
};
That was a lot simpler than
struct X {
      static const int id;
};

// in some cpp file:
const int X::id = 17;
 
 
1 hour later…
10:32 PM
I have three files, a.cpp, b.cpp and b.h. I am trying link and build an executable, but keep failing
here's what I have
 
2 messages moved from Lounge<C++>
this is not enough to solve the problem
@DemCodeLines pick one: multiple definitions, missing definition, missing declaration, templates in a header, missing include, definition in a header
 
10:50 PM
I think we had a quick discussion in the normal C++ room, which has already ended. Thanks for moving the original question here and the help.
 
There's no such thing as "the normal C++ room"
 
Quite obviously I was not aware that the room had been split into a "general discussion" and a QA room and I found his response to be a bit rude. It's fine though.
 
11:38 PM
@DemCodeLines There's the Lounge, which is mostly for people suffering from C++ induced PTDS, C++ transmitted AIDS, and so on. This is the only one (on SO, of which I'm aware) that's directly related to programming in C++.
3
 
Do I need to pass iterators or I could actually pass a set somehow without defining custom overload?
Damn it looks plain bad, why can't there be overloads for taking whole containers?
 

« first day (516 days earlier)      last day (2343 days later) »