Comment by rmn on Why is the size of a character sizeof('a') different in C...
This is pretty much a generic answer given the above code, :P
View ArticleComment by rmn on A C++ syntax question involving non trivial templating and...
Your answer to question two seems reasonable, thanks. However, the syntax of question 1 seems pretty much off to me.. Even more so since the template argument (typename S) isn't used in the friend...
View ArticleComment by rmn on A C++ syntax question involving non trivial templating and...
It's not the syntax itself that I'm asking about, but its difference from what I would guess it should be - from looking at the rest of the language. Perhaps you disagree, which is - as you said...
View ArticleComment by rmn on A C++ syntax question involving non trivial templating and...
The line 'template <typename S>' would define the relevant S, I don't understand your point. It is just the same as if I would define two clashing names anywhere in the class.. You explanation to...
View ArticleComment by rmn on Unit Testing Private Method in Resource Managing Class (C++)
It doesnt matter. private/public access is only enforced by the compiler, and doesnt exist in run time. so it would work just the same. Just use this define before the include of the header you're...
View ArticleComment by rmn on Help with geometry problem - don't have any idea
@poita incorrect. each flood fill should just overrun every square it gets to, besides the walls ofcourse. then you have at most 1 flood fill per square, which is very reasonable, and alot easier to...
View ArticleComment by rmn on Sleeping in the kernel using set_current_state
I'm not sure you're right -- what about interrupts and preemption (after your time slice is up) ?
View ArticleComment by rmn on Sleeping in the kernel using set_current_state
the question is what happens if we get rescheduled (due to normally consuming our time slice, or because an interrupt has occurred) after line 4254 and before line 4255
View ArticleComment by rmn on How to expand variadic arguments in a macro?
Seems very similar to efesx.com/2010/08/31/overloading-macros and efesx.com/2010/07/17/… You are most welcome to have a look.
View ArticleComment by rmn on compare function in inbuilt qsort function
@JimBalter You're right, I haven't noticed its C - my apologies. I've upvoted your reply so its first, and I'll let mine stay.. maybe he'll upgrade to c++ sometime :)
View ArticleComment by rmn on Maximum size of Receive Buffer/Queue in udp socket
@AyeshaHassan, right. There's a shared socket buffer maintained by the operating system, from which you pull data through recvfrom() and the likes.
View ArticleComment by rmn on Hanoi Tower amount of combination?
@TimurKukharskiy, you are slightly wrong since to store values between 0 and 1000 you'll need at least a short (two bytes, since 1 byte isn't enough), and that will lead to roughly 2KB of storage for...
View ArticleComment by rmn on comparing two vectors, make it more efficient
I imagine the first thing any such implementation would do is compare array sizes before looping tho :)
View ArticleAnswer by rmn for Is there a way to have a single static variable for a...
The syntax fortemplate <class T> friend class Foo<T>;istemplate <class T> friend class Foo;(which means that every instantiation of Foo is a friend of the class you define it in)So...
View ArticleAnswer by rmn for Find duplicates between arrays
What you are looking for is just a set of the two arrays (set contains every element once at most). The solution in c++:#include <set>int main () { int a[] = { 1,2,3 }; int b[] = { 4,2,3 };...
View ArticleAnswer by rmn for Working program gets an Illegal instruction fault on 'clean...
Quoting: "The development machine is an Intel Core2 Quad and the clean machine is a Pentium 4 Dual. I assume g++ defaults to using a common subset of x86 instructions and that the processor difference...
View ArticleAnswer by rmn for c++ deque vs queue vs stack
deque supports insert/pop from back & frontqueue only supports insert to the back, and pop from the front. You know, a FIFO (first in first out).
View ArticleAnswer by rmn for Program crash with pointers trying to make strcpy-like
Fixed: #include <iostream> using namespace std; void mycpy(char *b , char *a); int main() { char *original = "this is a text" ; char copied[30]; // you need to actualy allocate space // (this is...
View ArticleAnswer by rmn for Disjoint Set ADT Implementation in C++
You have way too many requirements, we're not here to do your homework for you.Have a look at http://en.wikipedia.org/wiki/Disjoint-set_data_structure
View ArticleAnswer by rmn for C++ memory table
Can std::vector<std::vector<std::string/boost::any?> > be considered a candidate?
View ArticleAnswer by rmn for How do I call a C++ function from C?
If you use a C++ compiler (say g++ instead of gcc), you can call C++ code from your C code seamlessly and everything will work just fine.This will be the case since unless you're doing something really...
View ArticleAnswer by rmn for Are there tools to transform source code in C++ to the...
You could work around the problem by placing a deliberate error inside the instantiation or its parameters, then you'd have the compiler (assuming decent versions: gcc 4.8, clang, etc) output something...
View ArticleAnswer by rmn for How to Divide a String Into char Arrays
What do you mean? A C\C++ string is essentially an array of character.. If you have a pointer to a char (=string) then there's your array. Otherwise if you have an std::string, you can use its .c_str()...
View ArticleAnswer by rmn for vars.c:4:1: error: expected declaration specifiers or '...'...
Working version of your code:#include <stdio.h> int main() { int num = 100; float pi = 3.1415926536; printf( "Integer is %d \n",num); printf( "Values are %d and %f \n",num,pi); printf( "%%7d...
View ArticleAnswer by rmn for Conditional Lexicographical Permutations
What you're asking about is called a factorial base, and you could just advance the counter with the correct amount when needed. You can read more about it here:...
View ArticleAnswer by rmn for Reading and writing Large files in C
I imagine that name = (char**)malloc(MAXINT*sizeof(char*)); actually fails, you should check for a NULL return value there.
View ArticleAnswer by rmn for Logic of #define (microchip xc8 compiler)
To make sure you understand exactly whats going on, I'd just suggest experimenting with the preprocessor and checking out its output (before compilation, right after preprocessing & subsitutions...
View ArticleAnswer by rmn for Is it a sensible optimization to check whether a variable...
It would be sensible if you had read-write locking semantics involved, whenever reading is usually less disruptive than writing.
View ArticleAnswer by rmn for comparing two vectors, make it more efficient
I imagine any implementation you'd have would start with verifying that array sizes are equal and then continue with going over the elements one by one and comparing them (returning false as soon as it...
View ArticleAnswer by rmn for random function which generates 1 or 0 with given probability
You just need to generate a random flaot from [0,1]. If its >p then return 1, otherwise 0.
View ArticleAnswer by rmn for Evaluate a string with a switch in C++
You can only use switch-case on types castable to an int.You could, however, define a std::map<std::string, std::function> dispatcher and use it like dispatcher[str]() to achieve same effect.
View ArticleAnswer by rmn for I am new to threads, What does this compile error mean?
You're passing a member function instead of a global, normal, one.Just define:void updateMessages(void *) {static ClientHandler c;// use c..}
View ArticlePrinting the contents of a file using the #include directive (preprocessor)
Say I have a file, t.txt, that contains the following two lines:one twoNow, I would like to write a program which will #include that file somehow and print its contents, nothing more. That is, I want...
View ArticleSleeping in the kernel using set_current_state
I've been reading http://www.linuxjournal.com/article/8144 and thinking about the following situation:4253 /* Wait for kthread_stop */4254 set_current_state(TASK_INTERRUPTIBLE);4255 while...
View ArticleAnswer by rmn for Pure virtual function with implementation
You'd have to give a body to a pure virtual destructor, for example :)Read: http://cplusplus.co.il/2009/08/22/pure-virtual-destructor/(Link broken, use archive)
View ArticleAnswer by rmn for When to use static keyword before global variables?
The correct mechanism for C++ in anonymous namespaces. If you want something that is local to your file, you should use an anonymous namespace rather than the static modifier.
View ArticleWould you use num%2 or num&1 to check if a number is even?
Well, there are at least two low-level ways of determining whether a given number is even or not: 1. if (num%2 == 0) { /* even */ } 2. if ((num&1) == 0) { /* even */ }I consider the second option...
View ArticleAnswer by rmn for Calculating time by the C++ code
Here is a portable, self-contained, short implementation of exactly what you need: https://web.archive.org/web/20151123102016/http://efesx.com/2009/08/19/portable-measurement-of-execution-time/If the...
View Article