c

warnings in Eclipse

hello, can somebody please explain what does this warning mean undefined reference to 'WinMain@16' thanks in advance ...

Static Memory allocation & Portability

I have read Static Memory Allocation are done during Compile time. Is the 'address allocated' used while generating executables ? Now, I am in doubt how the memory allocation is handled when the code executable is transferred completely onto a new system. I searched for it but I didn't get any answer on the internet. ...

Is there a a C-like way to get item number from enum in java ?

Perhap this is a simple basic question Having an enum public enum TK{ ID,GROUP,DATA,FAIL; } Can I get the order number for example ID=0, GROUP=2, DATA=3, FAIL=4 ? This is a way to to that, but a weird and long one! =S public enum TK{ ID(0),GROUP(1),DATA(2),FAIL(3); int num; TK(int n) ...

What is the C runtime library?

OK, I know this is maybe the most stupid question ever asked here, but what actually is C runtime library and what is used for? I was searching, googling like devil, but I could find better than Microsofts: "The Microsoft run-time library provides routines for programming for the Microsoft Windows operating system. These routines automat...

In C, would !~b ever be faster than b == 0xff ?

From a long time ago I have a memory which has stuck with me that says comparisons against zero are faster than any other value (ahem Z80). In some C code I'm writing I want to skip values which have all their bits set. Currently the type of these values is char but may change. I have two different alternatives to perform the test: if ...

C program runs in Cygwin but not Linux (Malloc)

I have a heap allocation error that I cant spot in my code that is picked up on vanguard/gdb on Linux but runs perfectly on a Windows cygwin environment. I understand that Linux could be tighter with its heap allocation than Windows but I would really like to have a response that discovers the issue/possible fix. I'm also aware that I ...

Reading file and populating struct

Hi, I have a structure with the following definition: typedef struct myStruct{ int a; char* c; int f; } OBJECT; I am able to populate this object and write it to a file. However I am not able to read the char* c value in it...while trying to read it, it gives me a segmentation fault error. Is there anything wrong with my ...

Efective way to avoid integer overflow when multiplying?

Hi, I'm working on a hash function which gets a string as input. Right now I'm doing a loop and inside the hash (an int variable) is being multiplied by a value and then the ASCII code for the current character is added to the mix. hash = hash * seed + string[i] But sometimes, if the string is big enough there is an integer overflow ...

Counting number of searches

I updated my main and sequetialSearch and now it crashes when it runs. It compiles okay, but then crashes. main.c #include <stdio.h> #include <stdlib.h> #include <time.h> #include <stdbool.h> #include "percentage.h" #include "sequentialSearch.h" #define searchAmount 100 int main(int argc, char *argv[]) { int numbers[100]; int sea...

How to make an mutable C array for this data type?

There's this instance variable in my objective-c class: ALuint source; I need to have an mutable array of OpenAL Sources, so in this case probably I need a mutable C-array. But how would I create one? There are many questions regarding that: 1) How to create an mutable C-array? 2) How to add something to that mutable C-array? 3) H...

Trouble with Unions in C program.

I am working on a C program that uses a Union. The union definition is in FILE_A header file and looks like this... // FILE_A.h**************************************************** xdata union { long position; char bytes[4]; }CurrentPosition; If I set the value of CurrentPosition.position in FILE_A.c and then call a function in FILE_...

Which is faster for large "for" loop: function call or inline coding?

Hi, I have programmed an embedded software (using C of course) and now I'm considering ways to improve the running time of the system. The most important single module in my system is one very large nested for loop module. That module consists of two nested for loops that loops max 122500 times. That's not very much yet, but the proble...

bitfield mask calculation macro

We have a set of C macros, here, for using the preprocessor to do bitfield operations, and we run into warnings when attempting to use these macros in visual studio. The problem can be demonstrated very easily: #define BITFIELD_WIDTHMASK(Width) \ ((Width) >= 32 ? ~0x0ul : (1ul << (Width)) - 1) unsigned long foo(void) { return ...

How to combine two 32-bit integers into one 64-bit integer?

I have a count register, which is made up of two 32-bit unsigned integers, one for the higher 32 bits of the value (most significant word), and other for the lower 32 bits of the value (least significant word). What is the best way in C to combine these two 32-bit unsigned integers and then display as a large number? In specific: leas...

Declaring an array of character pointers (arg passing)

This is something that should be easy to answer, but is more difficult for me to find a particular right answer on Google or in K&R. I could totally be overlooking this, too, and if so please set me straight! The pertinent code is below: int main(){ char tokens[100][100]; char *str = "This is my string"; tokenize(str, toke...

Invoke web page from Linux C

Hi, I need to read all the HTML text from a url like http://localhost/index.html into a string in C. I know that if i put on telnet -> telnet www.google.com 80 Get webpage.... it returns all the html. How do I do this in a linux environment with C? ...

When is ¦ not equal to ¦?

Background. I'm working with netlists, and in general, people specify different hierarchies by using /. However, it's not illegal to actually use a / as a part of an instance name. For example, X1/X2/X3/X4 might refer to instance X4 inside another instance named X1/X2/X3. Or it might refer an instance named X3/X4 inside an instance n...

Concat wchar_t Unicode strings in C?

I'm a beginner, I play with FindFirstFileW() of the winapi - C. The unicoded path is: " \\?\c:\Français\", and I would like to concat "*" to this path of type wchar_t (then I will use it as an arg for FindFirstFileW()). I made two test cases of mine, the first is ansi_string() which seem to work fine, the second is unicode_string() - wh...

Round an integer to the nearest int that is lower than or equal to it and a multiple of 64

Given an integer x, how would you return an integer y that is lower than or equal to x and a multiple of 64? ...

C child read giving "resource temporarily unavailable"

So I have a file stream from a parent process to a child - and most of the time it works fine. However, when reading from it multiple times quickly, using fgets() will return NULL and the error is set to "resource temporarily unavailable". The problem is intermittent - and running the script that does the reads will sometimes have fgets ...