What does __FILE__ mean?

The realpath() function gives you the file-system path, with any symbolic links and directory traversing (e.g. ../../) resolved. The dirname() function gives you just the directory, not the file within it. __FILE__ is a magic constant that gives you the filesystem path to the current .php file (the one that __FILE__ is in, not the one it’s included by if it’s an … Read more

C++: Expression must have a constant value when declaring array inside function

There is a misconception here with what const means, probably because it’s a little confusing that this works: but this doesn’t: The issue is that the array size in an array declaration must be a core constant expression. Simplified, that means an expression that’s evaluatable at compile time to be a constant. That is true in the … Read more

What is the difference between const and readonly in C#?

Apart from the apparent difference of having to declare the value at the time of a definition for a const VS readonly values can be computed dynamically but need to be assigned before the constructor exits.. after that it is frozen. const‘s are implicitly static. You use a ClassName.ConstantName notation to access them. There is a subtle difference. Consider a class defined … Read more

Why is there no Constant feature in Java?

Every time I go from heavy C++ coding to Java, it takes me a little while to adapt to the lack of const-correctness in Java. This usage of const in C++ is much different than just declaring constant variables, if you didn’t know. Essentially, it ensures that an object is immutable when accessed through a special kind of pointer … Read more

Difference between char* and const char*?

char* is a mutable pointer to a mutable character/string. const char* is a mutable pointer to an immutable character/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you try to do so. For the same reason, conversion from const char * to char* is deprecated. char* const is an immutable pointer (it cannot point to any other location) but the contents … Read more

Why Is `Export Default Const` invalid?

const is like let, it is a LexicalDeclaration (VariableStatement, Declaration) used to define an identifier in your block. You are trying to mix this with the default keyword, which expects a HoistableDeclaration, ClassDeclaration or AssignmentExpression to follow it. Therefore it is a SyntaxError. If you want to const something you need to provide the identifier and not use default. export by itself accepts a VariableStatement or Declaration to its right. The following is fineexport default Tab; … Read more

How to convert a std::string to const char* or char*

If you just want to pass a std::string to a function that needs const char* you can use If you want to get a writable copy, like char *, you can do that with this: Edit: Notice that the above is not exception safe. If anything between the new call and the delete call throws, you will leak memory, as nothing will call delete for you … Read more