I'm busting my head but cannot find a solution for this. Please consider this scenario:
I have writers that want to write to non-blocking "queue" to another machine on the local network and have a reader that will read data (blocking mode if there are no writers) and do some job A and then return after a long hour and take next data.
...
I'm trying to inline some assembly code in my C code:
__asm { mov reg,val };
The problem: I want to define the register and value dynamically.
I know the 'val' can be a variable written in the C code, but I don't know how can I choose the register dynamically (i.e decide according to user input- register 'dh' or 'dl').
Any suggestion...
Is there a way to write an object in C/C++ that can be used from .NET? I would like to do it in a most simple way, the one used to extend basically all other languages, i.e. write an object in C, conform to the interface required by the language runtime, use the object from the language.
...
I am trying to display, set & modify PATH environment variable from a C program. I am doing something like this:-
char *cmd[] = { "echo", "$PATH", (char *)0 };
if (execlp("echo", *cmd) == -1)
But I am not getting the results.
...
I have structs like this:
struct Child
{
int foo;
char bar[42];
};
struct Parent
{
long foobar;
struct Child ** children;
size_t num_children;
}
I have defined an API like this:
struct Parent * ParentAlloc() { struct Parent* ptr = (struct Parent*)calloc(1, sizeof(struct Parent));
ptr->children = (struct Child**)calloc(S...
I'm trying to use assembly in C code using C variables.
My code looks like this:
__asm { INT interruptValue };
Where 'interruptValue' is a variable I get from the user (e.g 15 or 15h).
When I try to compile I get:
Assembler error: 'Invalid instruction
operands'
I don't know what is the correct type for interruptValue . I trie...
void problem3(void) {
int overflowme[16];
int x = (int) problem3; // x is the address of the first instr for problem3
printf("hello world\n");
overflowme[17] = x;
I'm wondering what does the (int) do in C programming.
...
I would like to run a GTK+/C program line by line with some debugger. I have never debugged a Linux program so where can I find instructions to a very beginner on how to debug code? I have just an idea that I have to download the sources from net, compile the project with debug symbols and run sources through DDD or GDB. So can anyone gi...
Title pretty much sums it up. When I declare a struct in C, am I guaranteed that the members will be initialized to some specific value, such as 0 for integer members?
EDIT:
So, let's say I have a struct that looks like:
typedef struct
{
int a;
} my_str;
and I declare:
my_str thing1;
globally. As per some of the answers, thi...
Could find a similar thing for C here.
I need to break a sentence into a an char array based on occurrence of a character example: %
Example
If my sentance is my%healthy%dog then i should be able to get my, healthy and dog separately.
This could be in a loop as well.
tx
...
int main(void){
float x =1;
float y =2;
while (x<y){
x = x +1 ;
y = y +1;
}
printf("x is %d\n", x);
printf("y is %d\n", y);
}
I would expect x and y to increase to the point we run out of bits, but it seems like x and y is alway 0 in this case...
...
I just discovered the existence of markers in vi. How do you use it, what do you know about them? are they useful, say for a C++ developer?
...
hello, i'm getting some troubles with QT it builds with option "-lrt"
i'm using mac os 10.6 with QT creator 1.2.1, heeeeeeelp !
this is the full build command :
g++ -headerpad_max_install_names -o
AMiningCoreTest main.o tokenizer.o
DictionnaryToolBox.o mysql.o btree.o
BTreeDataTable.o tcaccess.o
-L/Library/Frameworks -L/...
The following code causes an error and kills my application. It makes sense as the buffer is only 10 bytes long and the text is 22 bytes long (buffer overflow).
char buffer[10];
int length = sprintf_s( buffer, 10, "1234567890.1234567890." );
How do I catch this error so I can report it instead of crashing my application?
Edit:
...
class scanner
{
private:
string mRootFilePath;
static int AddToIndex( const char *,const struct stat *,int);
public:
scanner(string aRootFilePath){
mRootFilePath = aRootFilePath;
}
string GetFilepath(){
return mRootFilePath;
}
...
I've created a static library in GCC, but I'd like to hide most of the symbols.
For example, test1.c:
extern void test2(void);
void test1(void) {
printf("test1: ");
test2();
}
test2.c:
extern void test1(void);
void test2(void) {
printf("test2\n");
}
library_api.c:
extern void test1(void);
extern void test2(void);
void libra...
I'm trying to use the BN_* functions in OpenSSL. Specifically, I have the following code:
#import <openssl/bn.h>
BIGNUM * num = BN_new();
BN_set_word(num, 42);
char * buffer = malloc((BN_num_bytes(num)+1) * sizeof(char));
buffer[BN_num_bytes(num)] = '\0';
int len = BN_bn2bin(num, buffer);
printf("42 in binary is %s\n", buffer);
Howev...
If I got the C99 restrict keyword right, qualifying a pointer with it is a promise made that the data it references won't be modified behind the compiler's back through aliasing.
By contrast, the way I understand the const qualifier is as compiler-enforced documentation that a given object won't be modified behind the back of a human be...
I want to be able to have a user input a-z or c-z or c-p or whatever and have it return the actual letters between those two. I figured I would have to use ASCII numbering so I could use these steps:
1) Look for '-', if true
2) Look at first char that was input(char a in a-z), find ASCII #
3) Look at last char that was input (char z ...
I'm looking for good books on concurrent programming in C in the Unix environment. They need to cover classic concurrency, Unix multi-processing, and POSIX thread. Most of the books I have found are not for C or Unix. Keep in mind that I am not expecting one book to cover all of that though it would be great if such a book existed.
The ...