« first day (320 days earlier)      last day (2524 days later) » 

4:59 AM
One advantage of weak typing(say C++), Type conversions can take advantage of certain features of type hierarchies, like programming on interface. With strongly typed, static typed languages, no type conversion, so no chance to programming on interface
 
 
4 hours later…
8:43 AM
Is anybody available to help figure out why a vector<unique_ptr> throws an exception on move, but only if it has a certain derived class in it?
SimpleDirectory.cpp : Line 12
If it only hits line 9, then it's fine.
 
nwp
9:26 AM
@David Not enough code to reproduce. Make a mcve and put it on ideone.com or coliru.stacked-crooked.com so it shows the relevant error there.
 
10:20 AM
@David The correct way to write code is not to do it, if you need directories etc, use a library like boost::filesystem
Also virtual unique_ptr<Directory> parent() is weird, because this means the child completely owns the parent
I would just return pointers, if you really actually need the parent
Also get rid of pointers and virtual functions (this isn't 90s java), you can have std::vectors<FileSystem_Object> where FileSyste_Object has a member called if_folder, or even better "flags" (for other info, for example)
 
 
4 hours later…
Anonymous
2:24 PM
// Is it correct to do:

extern union ASTNode;

// Then:

extern struct AssignmentExpression : ASTNodeWrapper
{
ASTNode lhs;
ASTNode rhs;
};

// then:

extern union ASTNode
{
AssignmentExpression assignExpr;
};
 
no, this won't compile
 
Anonymous
My message was not formatted...
 
Anonymous
Hum...
 
also, lol, union
May 5 at 13:41, by Szymon Marczak
user image
 
Anonymous
Ah will do this
 
Anonymous
2:26 PM
Why? union is wrong?
 
std::variant or boost::variant works way better
 
Anonymous
I heard much about this variant, but does it occupy more memory?
 
it needs to store the info which type are you currently storing, which you would need to store anyway
so, no, it doesn't
 
Anonymous
Ah! So I won't need of storing the type. I'll try to learn to use it
 
Anonymous
But I still need to use the ASTNode type
 
Anonymous
2:29 PM
Inside the union structs
 
extern is not applicable to types, only to functions, so the syntax is wrong
but guessing what you want to do
you want to store a syntax tree, so you need recursive data types
by default, the members are stored directly
 
Anonymous
Yes... I think using variants
 
Anonymous
won't let ASTNode be re-declared with new parameter types
 
Anonymous
template types*
 
so with unions
0
A: C++ - When to use pointers to class data members?

milleniumbugThis is a box: it has a volume of about one cubic meter, so it can only store objects that have total volume of one cubic meter. And it definitely can't store two identical boxes as itself. Note that each one of these two boxes would also need to contain two boxes like it, and so on, and so on...

^ about storing the values directly
 
Anonymous
2:38 PM
i.e. variant<nothing?> ASTNode; struct NodeUsingASTNode { ASTNode lhs; ... }; variant<NodeUsingASTNode> ASTNode; I'll look at this question
 
3
A: Parsing Text to Make a Tree Data Structure

seheSpoiling the fun with an answer you can't use anyway if it's homework: A minimal implementation with Boost Spirit Qi: #include <boost/spirit/include/qi.hpp> namespace qi = boost::spirit::qi; typedef boost::make_recursive_variant< std::vector<boost::recursive_variant_>, std::string>::t...

Actually boost::variant is a perfect fit for recursive data structures, very common in parsing
^^ here's a sample usage
 
 
6 hours later…
8:47 PM
const void **array = malloc(INITIAL_LIST_SIZE*sizeof(const void *));
How can we write this line that can work on any(32/64) bit architecture?
 
garbage code
even by C standards
if this is C++ then I'll say "why the hell you're not using std::vector or std::unique_ptr" and "why are you using an array of void*"
 
This is C code
 
in that case it's still bad, but for different reasons
it correctly allocates an array of INITIAL_LIST_SIZE of pointers, but it violates DRY
const void **array = malloc(INITIAL_LIST_SIZE * sizeof *array);
also you want overflow protection here
 
size_t or sizeof?
 
???
size_t is a type, and sizeof is an operator
to elaborate on overflow protection: if INITIAL_LIST_SIZE is too big, it will overflow and you'll get a much smaller value passed to malloc (let's say M), the malloc will return a memory block of size M, but the code assumes it's INITIAL_LIST_SIZE, which will result in buffer overflow
 
9:08 PM
C compiler is silently converting void * to const void ** unlike C++ compiler
 

« first day (320 days earlier)      last day (2524 days later) »