Reputation
1,194
Top tag
Next privilege 2,000 Rep.
Edit questions and answers
Badges
9 13
Newest
 Yearling
Impact
~66k people reached

  • 0 posts edited
  • 0 helpful flags
  • 356 votes cast
Apr
15
comment Should I add 1 to my unknown string size when I create a char array to hold it via malloc?
Would also like to point out that whenever you know the length of a C string you should be using the "mem*" functions instead. Like memcpy(). The "str*" functions are a waste of time, looking for the zero terminator when you already know the length.
Apr
15
comment Should I add 1 to my unknown string size when I create a char array to hold it via malloc?
Ask yourself what will happen if you don't add room for that zero.
Apr
6
comment Should temporary files be saved to /tmp or the current working directory?
Definitely check the environment for the location of temporary files and never hard-code /tmp. Because a shared tmp has security issues, one mitigation I have often seen is to create per-user /tmp directories with no read-write permission for anyone else. It removes possible race conditions and symlink attacks.
Oct
10
comment Refactoring Switch Statements and is there any real use for Switch Statements at all?
@DavidArno: "the complete opposite"? The way I read it we said exactly the same thing. How can it be opposite?
Sep
2
comment Testing a windows game application against older versions of windows
@user2783034: You could use old desktops too but I think they use up too much space. Laptops can just sit in a small pile while not in use for testing.
Aug
3
comment Is storing data directly in a list node better than storing a pointer to data?
Some Gnome software changed to using GObject and GList, many years ago. The resulting 64-bit bloat from 10 MB RAM usage to 150 MB disgusted me. That was a 15X growth! For a RSS reader! Point is, try using a simple vector or array of the Content. No list. No pointers.
Feb
22
comment How to respond to a rude bug report?
@EricLippert: That bug report was handled very professionally. Although I agree with the reporter: doing anything with buffers in C without checking values first IS utter plebbery.
Feb
19
comment Why are there so few C compilers?
@supercat: Ah, a good weird one with overflows and integer promotion rules. It hinges on using 2 or 2u apparently.
Feb
13
comment Is throwing an exception an anti-pattern here?
I know that hardly anyone cares anymore but seriously. If you were implementing something like Redis would you really do a contains() call and then a get() call? Both calls need to hash or tree-search. The duplication is a pointless waste of time. If you possibly can, return the value and a "found" flag.
Feb
4
comment Why doesn't Java have optimization for tail-recursion at all?
Using recursion in C or Java always looks like stunt programming to me. No real reason for it, does not fit into the language, and serves only to confuse people.
Jan
3
comment Why are virtual machines required?
@TomJ: .NET also has an AOT compiler which it uses on installed library code. Not on applications, for some reason.
Dec
11
comment Is there ever a reason to use an array when lists are available?
@Mert: I believe (almost certain) that boundary checks are removed by the compilers when the usage is obviously correct such as in a loop with correct end checks.
Nov
24
comment Why is polling accepted in web programming?
+1 for long polling. Look up Comet en.wikipedia.org/wiki/Comet_%28programming%29
Nov
13
comment What did people do before templates in C++?
@IdeaHat: For generic functions look at qsort in the C library. It can sort anything because it takes a function pointer for the comparison function and passes a pair of void*'s.
Oct
7
comment Move semantics in C++ - Move-return of local variables
A move must always leave the object in a destructible state.
Aug
6
comment Why is the complexity of fetching a value from an array be O(1)?
Your question seems to assume that you are searching the array for a particular value. But the question you actually asked is about fetching a value from an array from an already known array index.
May
16
comment What is the responsibility or benefit of a Tokenizer?
Note that there are languages like Perl and C++ where the possible tokens are modified by where you are in the parsing. template<typename X<typename Y>> for example, changes the meaning of '>>' from '>>' to '>' '>'.
May
5
comment How can I hide my signature in a program?
Git allows the commit to set any timestamps that it wants. So I doubt you can rely on a git repo for any sort of evidence.
Apr
30
comment Why do C arrays not keep track of their length?
You have an statement in your question that isn't true. The heap manager does NOT have to track the length of each allocation. A slab allocator only has to know what slab the allocation is in. A 48 byte allocation goes in a 64 byte slab, but it could be 33 bytes or 51 bytes, the manager doesn't care.
Mar
11
comment How can you decompose a constructor?
I'd have to question if you ever intend to construct Enemy objects in code using literals. If you don't, and I don't see why you would, then build constructors that pull the data from a database interface, or a serialization string, or ...