c

Syscall from inline asm in x86_64 Linux?

Hi, Why does this print garbage instead of exiting my program gracefully? I use system calls this way on BSD, and I wonder what would I need to make it work in Linux. int main(int argc, char **argv) { __asm ("movq $1,%rax; movq $0,%rdi; syscall"); /* exit(0) ? */ return 0; } Thanks. ...

is it possible to store output of system call in windows?

for ex: i want to store output of system("dir"); Thanks & Regards, calvin ...

How to optimize a C for loop?

Hello, I have a performance issue in a bottleneck section in my code. Basically it's a simple nested loop. Profiling the issue reveals that the program spends a lot of time just incrementing both of the loop counters (++) and testing for termination (i/j < 8). Watching the assembly output I see that both counters don't get registers an...

ssh server C library?

I am looking for a C library that implements the server end of ssh. In particular, I am only interested in the subset that provides port forwarding. The ones that I have found so far (libssh2, NetSieben etc) seem to implement just the client. ...

Listing serial (COM) ports on Windows?

Hello, I'm looking for a robust way to list the available serial (COM) ports on a Windows machine. There's this post about using WMI, but I would like something less .NET specific - I want to get the list of ports in a Python or a C++ program, without .NET. I currently know of two other approaches: Reading the information in the HARD...

Calculating a round order of magnitude

For a simple project I have to make large numbers (e.g. 4294967123) readable, so I'm writing only the first digits with a prefix (4294967123 -> 4.29G, 12345 -> 12.34K etc.) The code (simplified) looks like this: const char* postfixes=" KMGT"; char postfix(unsigned int x) { return postfixes[(int) floor(log10(x))]; } It works, but...

Is there a tool which creates C header files for Delphi (Win32) DLLs?

Until now I have seen only tools and some information for the creation of Delphi code for a given C header file. However, in the 'Delphi first' case, there is a Delphi interface declaration and a generated DLL, and no C header. Are there tools which can extract the necessary information and build a C header file for a DLL? Such a tool ...

How to show function prototype in Emacs?

While in C-mode I can jump to a function using M-. on the function name....is there a way i can simply display the function prototype? (preferably as a tooltip or so) I often struggle to remember the exact order and types required by a given function. ...

sprintf question in C

Hi I have a very simple sprintf question. int STATUS = 0; char test[100]; int n = sprintf( test,"%04x", STATUS ); printf ("[%s] is a %d char long string\n",test,n); for(i=0 ; i<4 ; i++) { printf("%02x", test[i]); } printf("\n\n"); The output of this code is 30303030 which is not what I intend to have as output. Basi...

C Convert String to Ints Issue

I'm trying to parse some input on an embedded system. I'm expecting something like this: SET VARNAME=1,2,3,4,5,6,7,8,9,10\0 When I'm converting the separate strings to ints, both atoi() and strtol() seem to be returning 0 if the string begins with 8. Here is my code: char *pch, *name, *vars; signed long value[256]; int i; #ifdef UA...

How to write a function that gets a linked list of any node type and frees the memory used by it?

I'm sure some of you already experienced it. I have two linked lists of different types and I have two distinct functions that free the memory used by them. Those two functions are identical except for one thing. Generally a function that frees a list would looks like this: void free_list(T *p) { T *next; /* here */ while (p...

What is a good unix alternative to DDD (Data Display Debugger)?

I am developing c on linux using vim and debugging using ddd. However I find that ddd performs very poorly at scrolling on this machine so its sometimes very frustrating to use. I like the way that ddd maps fairly closely to the gdb command set as this means I am free to use gdb commands when I choose, but using gdb itself is not an opt...

Memory location of enum value in C

I think I've read somewhere that it is illegal to take the address of an enum value in C (enum values not being lvalues; however, I can't find any information on this now). Is that correct and, if so, why? Edit: Here's an example that clarifies what I mean by "enum value" above. I mean taking the address of first_value below, not tak...

Differences in Macro ## concatenation operator between Visual-C++ and gcc

Hello, I'm having a macro like this ( not exactly, but function is quite equivalent): #define STRUCTMEMBER(Member,Value) GlobalStructInstance. ## Member = Value ... STRUCTMEMBER(Item,1); This works perfectly in Visual C++, but gcc 3.4.5 (MingGW) yield the following error: pasting "." and "Item" does not give a valid preprocessing to...

Align native code on fixed size memory boundaries with GCC/G++/AS ?

I have a C function that contains all the code that will implement the bytecodes of a bytecode interpreter. I'm wondering if there is a way to align segments of the compiled code in memory on fixed size boundaries so that I could directly calculate the address to jump to from the value of the bytecode? Sort of the same way an array work...

What is easiest way to calculate an infix expression using C language?

Suppose the user inputs an infix expression as a string? What could be the easiest ( By easiest I mean the shortest) way to evaluate the result of that expression using C language? Probable ways are converting it to a postfix then by using stacks.But its rather a long process. Is there any way of using functions such as atoi() or eval()...

C compiler from where ?

I want to learn C language (is this something good ?) and i didn't know from where i can download the language to my PC ? and are this FREE or must pay for ? ...

What is c printf %f default precision?

I'm curious: If you do a printf("%f", number); what is the precision of the statement? I.e. How many decimal places will show up? Is this compiler dependent? ...

Maintain SQL sort state throughout next query?

I saw this post but didn't understand if this was the same issue. My database can be sorted on each column. Once the db is sorted, how do I maintain that order after my next query? For example: Order db by age: sprintf(sql, "select * from Customer_Table ORDER BY age_ID LIMIT 100 OFFSET %s;", offset); then the user looks at the...

How can I get the size of a memory block allocated using malloc()?

Possible Duplicates: How can I get the size of an array from a pointer in C? Is there any way to determine the size of a C++ array programmatically? And if not, why? I get a pointer to a chunk of allocated memory out of a C style function. Now, it would be really interesting for debugging purposes to know how big the allocate...