c

Adding Compile Flags in Xcode

(I'm not sure if "flag" is the word I'm looking for, but I'll explain it.) I am trying to compile a program that uses the GMP big number library. But to be able to compile with GMP, I have to add -lgmp to the end of the command. For example, if I want to compile "program.c", I have to type gcc program.c -lgmp. This is easy from the comm...

How would you define a simple "min" method in obj-c

I want to define a min and max methods in a Utils class. @interface Utils int min(int a, int b); int max(int a, int b); @end But I don't want to have named parameters. It would be a too heavy notation. I wanted to use the C-style definition. But then [Utils min(a, b)] as a call doesn't work. What is my problem? Thanks in advance fo...

How to get the running of time of my program with gettimeofday()

So I get the time at the beginning of the code, run it, and then get the time. struct timeval begin, end; gettimeofday(&begin, NULL); //code to time gettimeofday(&end, NULL); //get the total number of ms that the code took: unsigned int t = end.tv_usec - begin.tv_usec; Now I want to print it out in the form "**code took 0.007 second...

understanding functions and pointers in C

Hi, This is a very simple question but what does the following function prototype mean? int square( int y, size_t* x ) what dose the size_t* mean? I know size_t is a data type (int >=0). But how do I read the * attached to it? Is it a pointer to the memory location for x? In general I'm having trouble with this stuff, and if anyb...

DBus Glib Send Signal - No signals being emitted.

I am attempting to send a signal out over the session message bus. I am able to call methods fine using d-feet dbus debugger with no problem. Unfortunately d-feet does not allow you to connect to signals to debug those. In replacement I am using dbus-monitor "type='signal'" to see if anything is sent. So far this works except for anythin...

GMP convert mpz to mpf

I am using GMP, and I want to be able to quickly convert an mpz to an mpf. I looked through the library and couldn't find much. The best thing I could think of was this: mpz_t x; /* Insert code here that assigns some value to x */ char buf[SIZE]; gmp_sprintf(buf, "%Zd", x); mpf_t y; mpf_set_str(y, buf); This solution requires repeate...

how to get the current opened applications in windows using c++ or vb.net?

i need the current opened applications(those that appear in the task bar) and NOT the currently running processes. thanks ...

Platform independent size_t Format specifiers in c?

I want to print out a variable for type size_t in c but it appears that size_t is aliased to different variable types on different architextures. For example on one machine (64-bit) the following code does not throw any warmings: size_t size = 1; printf("the size is %ld", size); but on my other machine (32_bit) the above code produces...

Equivalent of InterlockedIncrement in Linux/gcc

It would be a very simple question (could be duplicated), but I was unable to find it. Win32 API provides a very handy set of atomic operations (as intrinsics) such as InterlockedIncrement which emits lock add x86 code. Also, InterlockedCompareExchange is mapped to lock cmpxchg. But, I want to do that in Linux with gcc. Since I'm worki...

Error from gcc compiler

Hi, What does the following error mean: In function `get_ints`: `l` undeclared (first use in this function) Thanks, Josh ...

Pass by reference 2D dynamically allocated double array in C

Hi, I'm trying to convert my string into a dynamic array of doubles. Each space of my string represents a column, each ";" represents a new row. When this code runs, it only works for when *F[0][col]. When it gets to *F[1][col] it gives me the error "Unhandled exception at 0x00e4483c in CCode.exe: 0xC0000005: Access violation reading l...

Copying an array of characters

Hello, gcc 4.4.2 c89 I was just working on some pointers. However, with the program below I can't get it to copy the source to the destination. Even when I try and print in the for loop I can display the characters in the source, but the dest is blank. When the pointer returns the destination is empty. So it hasn't copied anything. I ...

priority queue, where to insert?

so I am having trouble implementing priority queue. For a priority queue, I need to find the first place where it is empty...that's where the element go, we will swap later..but I am having trouble figuring out the algorithm to find it. Here's what I have so far: void pq_insert(struct tnode* p) { struct tnode* curr=NULL; struct...

How does this pointer arithmetic work?

#include <stdio.h> int main(void){ unsigned a[3][4] = { {2,23,6,7}, {8,5,1,4}, {12,15,3,9} }; printf("%u",*((int*)(((char*)a)+4))); return 0; } The output in my machine is the value at a[0][1] i.e 23.Could somebody explain how is this working ? Edit: Rolling Back to old yucky code,exactly what was presented to me :P ...

Find out where PE file ends through PE header?

I want to append some binary data to the end of my executable. This is just to make my program into a single file. I tried using UpdateResource but I hit some bug inside it with my specific data, so I have to use another solution. So I need to know the original file size to determine if there is actually any data appended to it. Is it po...

HTTP PUT method implementation in C

I need to implement the HTTP PUT method in C using TCP socket. Can anyone help me out? ...

C/C++ bitfields versus bitwise operators to single out bits, which is faster, better, more portable?

I need to pack some bits in a byte in this fashion: struct { char bit0: 1; char bit1: 1; } a; if( a.bit1 ) /* etc */ Or: if( a & 0x2 ) /* etc */ From the source code clarity it's pretty obvious to me that bitfields are neater. But which option is faster? I know the speed difference won't be too much if any, but as I can use any of th...

What kind of data type is "long long"?

I don't know this type. Is that the biggest one from all? I think it is an integer type, right? Or is it a floating point thing? Bigger than double? ...

Can anyone explain this algorithm for calculating large factorials?

i came across the following program for calculating large factorials(numbers as big as 100).. can anyone explain me the basic idea used in this algorithm?? I need to know just the mathematics implemented in calculating the factorial. #include <cmath> #include <iostream> #include <cstdlib> using namespace std; int main() { unsig...

I need to link C program on a shared object with no section headers

I've written an interface to the code generator that lets me produce shared objects. Though I do not want o implement support for section header table because that's where the majority complexity of ELF file format remains in. GNU ld uses section headers for linking against shared objects. This means that when I try to put gcc link agai...