Assignment and comparison
Looking at the code: int i = 5; if (i = 0) { printf ("Got here\n"); } What does the C standard have to say about what will get printed? Or in more general terms does the assignment happen first or the comparison? ...
Looking at the code: int i = 5; if (i = 0) { printf ("Got here\n"); } What does the C standard have to say about what will get printed? Or in more general terms does the assignment happen first or the comparison? ...
simple script for connect server: #include "hiredis.h" int main(void) { int fd; unsigned int j; redisReply *reply; reply = redisConnect(&fd, "test.com", 6379); if (reply != NULL) { printf("Connection error: %s", reply->reply); exit(1); } reply = redisCommand(fd,"PING"); printf("PONG: %s...
The following code (a function prototype): void parse_ini(FSFILE *fp, void(*secFunc)(char*), void(*varFunc)(char*, char*)); presents errors when compiled: util\setup.c:38: error: syntax error before '*' token util\setup.c:38: error: 'parse_ini' declared as function returning a function util\setup.c:38: error: syntax error before 'voi...
hello, everyone, I have this piece of the code: void foo(int var, int var1) { printf("%d\n", var); printf("%d\n", var1); } void foo_for_foo( void (*some_function)(int, int)) { int x = 5; some_function(x, x); } int main() { void (*ptr_foo); // <- look here ptr_foo = &foo; foo_for_foo(ptr_foo); return 0; } does it matter how...
Hi, Can you please explain to me what is happening here? char data[128]; // Create char array of size 128. long * ptr; // Create a pointer. ptr = (long *) data; // ?? Mainly, what does the (long *) mean? Does it mean that the data is of type char, and I am casting the reference to data as a reference to a long? Thank you. ...
I have the following code: struct A { short b; }; struct B { double a; }; void foo (struct B* src) { struct B* b = src; struct A* a = (struct A*)src; b->a = sin(rand()); if(a->b == rand()) { printf("Where are you strict aliasing warnings?\n"); } } I'm compiling the code with the following c...
If I wanted to link the following objects and libraries, p.o → libx.a → p.o Where a → b denotes that b defines a symbol that is referenced by a. Would UNIX% gcc p.o libx.a be enough in the command line or do I need to do something like: UNIX% gcc p.o libx.a p.o Thanks. ...
I'm making a game that will allow content development and I'd like it to be sort of a DLL based system. But, my game works for Linux (X86 arch) , Mac OSX and 32 bit Windows. Is there a way I could allow content developers to compile only one thing and have it work based on the platform? I fear it might get confusing if there are 3 versio...
I have an update that is failing due to a constraint on the table, but sqlite3_exec only returns an error code of 1 instead of 19. How do I get the correct error code? ...
I have a problem with my code, good news is I actually pinpointed the problem, bad news is I do not understand why it is a problem. Also should this be return or exit? This is my getNums() function,...so far. first my code calls getLine() which gets the line and returns its character length. Then get nums is given, the line, length o...
I would like to control an RC model via USB from my computer. I don't need a real radio control, so controlling the servos directly through cables is sufficitent (yes, there will be cables between the model and the controlling unit). I thought I would build some microcontroller-based device which would be connected to the computer via US...
I'm continuing to learn C and would like to adhere to whatever is the current standard, but finding a good reference to that seems to be problem. From what I've found online (mostly through Google and Wikipedia) is that the current standard used today is C99, more formally the ISO/IEC 9899:1999 standard. When I'm writing C code, I ofte...
struct match { char men[64]; char women[64]; char menNum[1000]; char woNum[1000]; }; void printOut(); int matchMaking(struct match* p, struct match* q, int k); int main(void) { FILE* fin; FILE* fout; fin = fopen("input.txt", "r"); fout = fopen("out.txt", "w"); int matchNum = 0; int size; int i...
I want to forward packets by netfilter, so I want to get some c demos to get start, thanks ...
For example if I write to a particular memory location (ex: DMA transfer) how does it get affected in my cache? ...
I've attempted to follow the instructions from various places [1][2][3], but I keep getting link errors when attempting to use GLUT and OpenGL in Cygwin. Everything I try gives me a link error similar to: $g++ -Wall -pedantic -c -o triangle.o triangle.cpp $g++ -o triangle *.o -lglut32 -lglu32 -lopengl32 -o triangle triangle.o:triangle....
void main() { char c='0'; printf("%d %d",sizeof(c),sizeof('0')); } ...
Hi..I am trying to see if a given pair of (lat,long) will fall within a circular region. The centre of the circle is known (lat,long values) as well as the radius. The approcah I have used is: Calculate the distance between the centre and the given lat/long using Haversines formula. Formula: a = ( sin(delta_lat/2) )^2 + cos (vp_Curr...
Any help please, a week without geting the problem **C:>pager_OPTIMAL test 100 File used fifo-test, resident set size 200 Error restoring the reference stream position Error was:: Invalid argument*/* pt_entry pte[MAX_PAGE]; /* page table */ int mem_size; /* physical memory size in page frames */ list free_l...
The ISO C standard allows three encoding methods for signed integers: two's complement, one's complement and sign/magnitude. What's an efficient or good way to detect the encoding at runtime (or some other time if there's a better solution)? I want to know this so I can optimise a bignum library for the different possibilities. I plan ...