c

Compiling a C program with a specific architecture

I was recently fighting some problems trying to compile an open source library on my Mac that depended on another library and got some errors about incompatible library architectures. Can somebody explain the concept behind compiling a C program for a specific architecture? I have seen the -arch compiler flag before and have seen values ...

Behavior with primitive data types' value out of range & C99's PRI* macros

Say we have an 8-bit unsigned integer n (UINT8_MAX=255); what is the behavior of the compiler for n=256? Where can I find a table of default behavior when the value of a data type is out of range for different data types? Is there a pattern to how they behave when set out of range? #include <stdio.h> #include <inttypes.h> uint8_t n = U...

memory (leaks) after executing

I'm wondering why randomly after executing the ./a.out I get the following. Any ideas what I'm doing wrong? Thanks http://img710.imageshack.us/img710/8708/trasht.png ...

How to you find out what group the current user belongs to via c++?

Using my c++ program how can I find out what group the current user running my program belongs to? So my program need to figure out a couple of things : The current username of the user The group the user belongs to How can do the above 2 using c++ on a RedHat / Linux machine? ...

C/C++ packing signed char into int

hello I have need to pack four signed bytes into 32-bit integral type. this is what I came up to: int32_t byte(int8_t c) { return (unsigned char)c; } int pack(char c0, char c1, ...) { return byte(c0) | byte(c1) << 8 | ...; } is this a good solution? Is it portable (not in communication sense)? is there a ready-made solution, perha...

why does this code crash?

why does this code crash? is using strcat illegal on character pointers? #include <stdio.h> #include <string.h> int main() { char *s1 = "Hello, "; char *s2 = "world!"; char *s3 = strcat(s1, s2); printf("%s",s3); return 0; } please give a proper way with referring to both array and pointers. ...

best algorithm for swapping?

i have heard from a friend of mine that the best algorithm for swapping is " (a^=b^=a^=b)" where a and b are two integers to be swapped. but when i applied this using c language it resulted in crashing. can anyone of you fine people explain the possible reason for that? please suggest the best algorithm for swapping. thank you!!!! guys ...

Visual Studio 2008 C Drop down menu assist?

Is there an option to enable the drop down menu that appears when coding in other languages such as html/vb/ect for C in Visual Studio? ...

"Gtk-WARNING **: cannot open display: " when using execve to launch a Gtk program on ubuntu

Hi, I have the following c program which launches a Gtk Program on ubuntu: #include <unistd.h> int main( int argc, const char* argv[] ) { char *args[2] = { "testarg", 0 }; char *envp[1] = { 0 }; execve("/home/michael/MyGtkApp",args,envp); } I get "Gtk-WARNING **: cannot open display: " and my program is not launched. I ...

storing in unsigned char array

Hello everyone, i got a question about unsigned char array. How can i store an integer in the array continually? for example, i need to store 01011 to the array first. Then i need to store 101, how can i stored as 01011101 in the array? thanks for your help! ...

How to convert AS3 ByteArray into wchar_t const* filename? (Adobe Alchemy)

How to convert AS3 ByteArray into wchar_t const* filename? So in my C code I have a function waiting for a file with void fun (wchar_t const* filename) how to send to that function my ByteArray? (Or, how should I re-write my function?) ...

Loading MachineCode From File Into Memory and Executing in C -- mprotect Failing

Hi I'm trying to load raw machine code into memory and run it from within a C program, right now when the program executes it breaks when trying to run mprotect on the memory to make it executable. I'm also not entirely sure that if the memory does get set right it will execute. I am currently running this on Ubuntu Linux x86 (Maybe the ...

What is the difference between wmain and main?

So I have some class starting with #include <wchar.h> #include <stdlib.h> ant there is that function wmain. What is it different from main function i usualy use in my C classes? ...

Dynamic memory allocation for 3D array

Possible Duplicates: Malloc a 3-Dimensional array in C? dynamic allocation/deallocation of 2D & 3D arrays How can i allocate 3D arrays using malloc? ...

Can we use wmain() functions with Unix compilers or it'll work only on windows?

Can we use wmain() functions with Unix compilers or it'll work only on\for windows? ...

Does Function pointer make the program slow?

Hi guys. I read about function pointers in C. And everyone said that will make my program run slow. Is it true? I made a program to check it. And I got the same results on both cases. (measure the time.) So, is it bad to use function pointer? Thanks in advance. To response for some guys. I said 'run slow' for the time that I have comp...

Compiler is able to find function without matching .h file is updated?

Hello Friends, I'm writing a C University project and stumbled upon a compiler behavior which I don't understand. In this file http://code.google.com/p/openu-bsc-maximveksler/source/browse/trunk/20465/semester/tasks/maman14/alpha/maman14/assembler/phaseOne.c?r=112 I've added a call to function named freeAsmInstruction(). This function...

Cannot do a ncurses overwrite(curscr, savewin) correctly because I ripoffline() before

I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first, to put a title bar and the second time to put a menu bar on the top of the page. I need to dropdown some menus so I save the screen before I drop down the menus. In the InitMenu function, I have the following code: savewin = newwin (0...

What is the context of a task that is saved on stack when a task is blocked in VxWorks?

What is the context of a task that is saved on stack when a task is blocked in VxWorks? ...

mem-leak freeing g_strdup

I'm trying to free g_strdup but I'm not sure what I'm doing wrong. Using valgrind --tool=memcheck --leak-check=yes ./a.out I keep getting: ==4506== 40 bytes in 10 blocks are definitely lost in loss record 2 of 9 ==4506== at 0x4024C1C: malloc (vg_replace_malloc.c:195) ==4506== by 0x40782E3: g_malloc (in /lib/libglib-2.0.so.0.2200...