Quantcast
Browsing all 39 articles
Browse latest View live

Answer by rmn for C++ memory table

Can std::vector<std::vector<std::string/boost::any?> > be considered a candidate?

View Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article


Printing 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 Article

Sleeping 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 Article


Answer 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 Article

Answer 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 Article


Would 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 Article

Answer 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
Browsing all 39 articles
Browse latest View live