Reputation
2,109
Top tag
Next privilege 2,500 Rep.
Create tag synonyms
Badges
11 15
Impact
~60k people reached

  • 0 posts edited
  • 0 helpful flags
  • 174 votes cast
Aug
6
comment Are data type declarators like “int” and “char” stored in RAM when a C program executes?
itoa (literally, "integer to ASCII") and deduce that the memory location contains an int and not a char. Decompilers can even automate a lot of this. But it definitely is not true that there is some table giving data types for all memory locations (and except for global variables, memory locations get reused anyway). Things are different in managed platforms, where objects are tagged with type. But C and C++ have no such concept.
Aug
6
comment Are data type declarators like “int” and “char” stored in RAM when a C program executes?
@user16307: Actually, when 0x00000061 is output, it is treated as a by default. The display just gets glyph # 97 from the font table, which happens to look like a lowercase A. If you want to output it as a number, then the compiler will add the extra code for determining the individual decimal digits and sending the corresponding ASCII codes 0x39 0x37... the display looks up the glyphs 47 and 45 and what you see on your screen is 61. Of course, it doesn't make sense to repeat this code, so the compiler actually will insert a function call. A reverse engineer could see that call to
Aug
6
comment Are data type declarators like “int” and “char” stored in RAM when a C program executes?
@user16307: "Doesnt exe file include information about what address is what type of data?" Maybe. If you compile with debug data, the debug data will include information on variable names, addresses, and types. And sometimes that debug data is stored within the .exe file (as a binary stream). But it is not part of the executable code, and it is not used by the application itself, only by a debugger.
Jul
22
comment How do I handle setters on immutable fields?
setXYZ are horrible names for factory methods, consider withXYZ or the like.
Jun
27
awarded  Autobiographer
Jun
10
comment What is the “type” of data that pointers hold in the C language?
Again, existence of a big enough type is irrelevant, all that matters is whether the particular type which is named in the cast is big enough
Jun
10
comment What is the “type” of data that pointers hold in the C language?
@supercat: the requirements for casting to a integer type of insufficient size do not change depending on whether an integer type of sufficient size exists. You get unspecified results from the conversion but not undefined behavior (the conversion is guaranteed to produce some value of the result type)
Jun
9
comment What is the “type” of data that pointers hold in the C language?
This answer has the generally right idea, but fails on the specific claims. Coercing a pointer to integral type is not undefined behavior, and Windows HANDLE data types are not pointer values (they are not pointers hidden in integral data types, they are integers hidden in pointer types, to prevent arithmetic).
Apr
21
comment Big O Question about an algorithm with (n^2 + n) / 2 growth rate
"O(n!) is the same as O(1) for sufficiently low values of n" is just wrong. There has to be a better way to explain that "when n is kept sufficiently low, Big-O doesn't matter".
Mar
16
comment What is the reason of using an interface versus a generically constrained type
@NtscCobalt: It's more useful when you combine both parametric and interface generic programming. E.g. what LINQ does all the time (accepts an IEnumerable<T>, returns another IEnumerable<T> which is e.g. actually an OrderedEnumerable<T>)
Mar
16
awarded  Citizen Patrol
Mar
13
comment how to nicely use constant std::string in c++
Most certainly, but you'll need a definition somewhere, or suffer linker errors. Using a singleton would also avoid copying many strings many times.
Mar
13
comment how to nicely use constant std::string in c++
const is fine. The problem with the code in this answer is that the strings are non-static data members, so new copies are made for each class instance. There's no reason to have multiple copies of the same hardcoded string.
Mar
13
comment how to nicely use constant std::string in c++
The original question showed an approach that provides string objects, with a lot less copying.
Mar
12
comment how to nicely use constant std::string in c++
Are you aiming for maximum inefficiency? This makes a copy of nearly every string in the entire program each time one of them gets used!
Mar
12
comment how to nicely use constant std::string in c++
I have to disagree with nearly all of @CrazyEddie's comment. std::string does add overhead, namely dynamic allocation, and string copy, and a field for storing the size at runtime. The size of a std::string is calculated at runtime, the number of elements in a const char[] is a compile-time constant. The only advantage of std::string is the interface. Someone should provide a library of string manipulation functions that take character arrays as input and return RAII object (std::string or similar) of the needed size as output, thus both efficient and immune to buffer overflow.
Mar
10
comment what should be logger's position in the parameter list
Of course this has the drawback that the logger is unavailable to the constructor.
Feb
12
answered Is throwing an exception an anti-pattern here?
Feb
1
revised Would redrawing controls in c# give more performance?
added 159 characters in body
Feb
1
answered Would redrawing controls in c# give more performance?