c

C : Printing big numbers

Take the following : #include <stdio.h> main() { unsigned long long verybig = 285212672; printf("Without variable : %llu\n", 285212672); printf("With variable : %llu", verybig); } This is the output of the above program : Without variable : 18035667472744448 With variable : 285212672 As you can see from the a...

How can I find a Binary tree from a given Traversal Method?

How can I find a binary tree from a given traversal method (inorder,post-order,pre-order)? ...

Handling Partial return from recv() TCP in C

I've been reading through beejs guide to networking to get a handle on TCP connections. In one of the samples the Client code for a simple TCP stream client looks like: if ((numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) { perror("recv"); exit(1); } buf[numbytes] = '\0'; printf("client: received '%s'\n",buf); cl...

Null or terminator canary

Can I force the gcc to use a null canary or terminator canary, when SSP is enabled, instead of random canary? If so, how? ...

Flymake configuration error while programming in C

When trying to run M-x Flymake-Mode in Emacs I get: Flymake: Configuration error has occured while running (make -s -C ./CHK_SOURCES=helloworld_flymake.c SYNTAX_CHECK_MODE=1 check-syntax). Flymake will be switched OFF I am invoking the command in a buffer called helloworld.c: #include <stdio.h> int main(void) { printf("Hello World...

How to print a pound / hash via C preprocessor?

Hi, I need help doing the following: a preprocessor macro label(x) shall output "#x", e.g., #define label(x) ... if I call label(aname), the output shall be "#aname" I know, that the following tries were errors. #define label(x) #x // leads to "x" #define label(x) \#x // is \"x" #define label(x) "#x" // is "#x" (but not the cont...

Memory Fragmentation Profiler

Are there any good memory fragmentation profilers? (linux gcc version would be nice). Valgrind cannot analyze this because it uses custom malloc/free functions. Thanks, Andrew ...

What is the cleanest way to include and access binary data in VC++ Express?

I have some binary files that I'd like to embed in a dll I'm compiling with VC++ Express Edition. I have a couple ways to do it (like converting the data to arrays that I compile along with the code), but I'm not satisfied and I feel like I'm probably missing an easy, straightforward solution. What's the cleanest, easiest way to do thi...

How to print the error message of GetLastError() in a textual form?

Hi, how could the last error message be printed? It gives me an integer instead of a text message. Thanks. ...

What are efficient ways to debug an optimized C/C++ program?

Many times I work with optimized code (sometimes even involving vectorized loops), which contain bugs and such. How would one debug such code? I'm looking for any kind of tools or techniques. I use the following (possibly outdated) tools, so I'm looking to upgrade. I use the following: Since with ddd, you cannot see the code, I use gd...

Help interpreting gdb: segfault in function

I am trying to debug a segfault, and I have this output from gdb: (gdb) n Program received signal SIGSEGV, Segmentation fault. 0x08048af9 in parse_option_list (ptr=0x6f72505f <Address 0x6f72505f out of bounds>, box_name=0x696d6978 <Address 0x696d6978 out of bounds>, option_list=0x313a7974, num_elements=0x33313532) at submit.c:125 ...

I'm new to C, can someone explain why the size of this string can change?

I have never really done much C but am starting to play around with it. I am writing little snippets like the one below to try to understand the usage and behaviour of key constructs/functions in C. The one below I wrote trying to understand the difference between char* string and char string[] and how then lengths of strings work. Furth...

Getting started with SSE

Hello, I want to learn more about using the SSE. What ways are there to learn, besides the obvious reading the Intel® 64 and IA-32 Architectures Software Developer's Manuals ? Mainly I'm interested to work with the GCC X86 Built-in Functions. ...

Assembly Function to C Program without Parameter Passing or Return Value

I need to create an assembly function that adds two positive numbers together, called by a C program. The C program would look like this: #include <stdio.h> int main(void){ int a = 0; int b = 0; int c = 0; printf( "Enter first number: " ); scanf( "%d", &a ); printf( "Enter second number: " ); scanf( "%d", &b ); sum(); printf( "Answer ...

Problem with hex literal in string comparison

I'm reading in an NES ROM file, where the first four bytes are "\x4e\x45\x53\x1a", or NES\x1a. In my actual code, the given file can be arbitrary, so I want to check to make sure this header is here. However, I'm running into some trouble, which the following code demonstrates: #include <stdio.h> #include <string.h> int main() { FILE ...

What is a simple example of replacing c code with assembly to improve performance?

I've heard that game developers will sometimes replace parts of inner loops w/ assembly code to improve the performance. What is a simple example of this? Where does the assembly go? Just inline w/ the c code? Thanks! Edit: a code sample is greatly appreciated. ...

callbacks in jni

Is there any way to pass a callback to java code, from C. And the call returns immediately. Later on, after completing the task, the java code can invoke that callback. I have a C extension for php that calls a java store to store some items in it. The items can be retrieved from store in synchronous and asynchronous methods (I provide...

Are there any tools to migrate the interface from legacy GTK applications to a modern GTK Builder based application

I'm responsible for a number of legacy C based GTK applications which are starting to show their age. I'm toying with the idea of re-implementing some of them in a more modern framework. Are there any tools which can help migrate a hand-built C based GTK interface into a GTK Builder based XML interface description? My aim would be to sep...

Error on server/client c program: "Connect: socket operation on non-socket"

I'm working on a socket program and everything seems fine.However after i compiled and run the server, i compile and run the client. But there is a problem in connect() function and even socket is ok client does not connect or server does not accept connection... While compiling, i got no errors. but after client has ran : error is ...

Easy way to display a continuously updating image in C/Linux

Hi, I'm a scientist who is quite comfortable with C for numerical computation, but I need some help with displaying the results. I want to be able to display a continuously updated bitmap in a window, which is calculated from realtime data. I'd like to be able to update the image quite quickly (e.g. faster than 1 frame/second, preferab...