Question:
How to view call stack, return value and arguments of the simply program below, with dtrace
/** Trival code **/
#include <stdio.h>
int
foo (int *a, int *b)
{
*a = *b;
*b = 4;
return 0;
}
int
main (void)
{
int a, b;
a = 1;
b = 2;
foo (&a, &b);
printf ("Value a: %d, Value b...
I'm trying to write the equivalent of an enum in C++ going in steps of eight instead of one, like
enum
{
foo,
bar = 8,
baz = 16,
};
There will be a lot of entries, new ones will be added at intervals, and for clarity they really want to be written in an order other than order of entry, so it would be nice not to have to ke...
I have found examples of how to fork multiple children by having something like this:
if ( fork() = 0 ) {
//In child
} else {
if ( fork() = 0 ) {
//in second child
But if I don't know how many children I am going to need, how might I do this?
For instance, if I have a linked list of commands, and I want to fork and exe...
Running:
#include <stdio.h>
int main(int argc, char *argv[]) {
const char *exp = "10-2+3*5";
char tok[255];
sscanf(exp, "%[^+-*/^]", tok);
printf("%s\n", tok);
sscanf(exp, "%[^-+*/^]", tok);
printf("%s\n", tok);
return 0;
}
Would output:
10-2
10
But why?
...
I'm writing my own unix terminal and I'm running into a problem executing commands:
First I take the user input and store it into a buffer, then I separate the words and store them into my argv[] array.
i.e
command is "firefox" to launch firefox which is stored in argv[0]
How do I launch the command? This is what I'm trying to do, but...
I am doing this..
value >> 3;
It is always going toward negative side.How do I round toward zero with right shift division?
...
Our team uses svn to manage our source. When performing a re-factor on a C file, I occasionally both change functions and move them within the file. Generally I try to avoid moving functions, because it makes the default svn diff get a bit addled about what's going on, and it often provides a diff which is more confusing than it needs to...
The C standard guarantees that size_t is a type that can hold any array index. This means that, logically, size_t should be able to hold any pointer type. I've read on some sites that I found on the Googles that this is legal and/or should always work:
void *v = malloc(10);
size_t s = (size_t) v;
So then in C99, the standard introduce...
Hi
In the following code, I copy a string in to a char* str, which is 10 characters long, using strncpy().
Now according to strncpy() manual, "Warning: If there is no null byte among the first n bytes of src, the string placed in dest will not be null terminated. " which is exactly what happens here.
The source string is 26 charcter...
Is there a tool for code coverage for C language.
I know there are many. But I wanted something like perl Devel::cover.
Where I get:
Line coverage
Branch Coverage
Condition coverage
Subroutine coverage
And all this in a nice HTML output.
Is there anything like this for C?
...
we are trying to port our application from HP machine to AIX machine.
it was running fine on HP machine but now its failing in malloc_y funtion.
but we cant find any clue for this.
who is calling this malloc_y function??
please advice.
...
Okay lets say I have a string such as this in a text file:
((( var1 AND var2 AND var3) OR var4) AND ((var5 OR var6) AND var7))
after parsing this into the c program and the vars are handled and set correctly it will end up looking something like this:
((( 1 AND 0 AND 0) OR 1) AND ((0 OR 1) AND 1))
Are there any useful libraries out...
Here is the question, How did C (K&R C) look like? The question is about the first ten or twenty years of C's life?
I know, well I heard them from a prof in my uni, that C didn't have the standard libraries that we get with ANSI C today. They used to write IO routines in wrapped assembly! The second thing is that K&R book, is one the be...
Hello,
Consider the following C code:
int c=((0xa3>>6)&0x1f)|0xc0;
printf("%d\n",c);
It correctly prints out 194 (0xc2). If I write the same thing in wcalc, the result is 195, or 0xc3. Is this some sort of precision error? Is this expected behavior? floor and ceiling functions do not work... or, to be more specific, floor works f...
In trying to figure out whether or not my code's inner loop is hitting a hardware design barrier or a lack of understanding on my part barrier. There's a bit more to it, but the simplest question I can come up with to answer is as follows:
If I have the following code:
float px[32768],py[32768],pz[32768];
float xref, yref, zref, delta...
Hi,
So I have megabytes of data stored as doubles that need to be sent over a network... now I don't need the precision that a double offers, so I want to convert these to a float before sending them over the network. What is the overhead of simply doing:
float myFloat = (float)myDouble;
I'll be doing this operation several million t...
I'm trying to create a DLL that exports a function called "GetName". I'd like other code to be able to call this function without having to know the mangled function name.
My header file looks like this:
#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif
EXPORT TCHA...
I have done a lot with Java but I am currently trying to learn c. I am trying to make a program to convert a number from decimal to binary.
Here is what I have:
#include <stdio.h>
#define LENGTH 33
int main( int argc, char*argv[ ] )
{
unsigned int number, base, remainder, x, i;
char result[LENGTH];
puts( "Enter a decimal value, a...
Hi I'm working on a unix shell and I'm running into two problems. I was wondering if any of you could help me out. My first problem is that the shell is not waiting for the child process to terminate. I can actually go type more commands while the child process is running. My second problems is in the following two lines. I'm not getting...
I want to refine my C skills and have been thinking of trying to write my own zip and unzip program. This seems hit on a lot of areas, CPU/HDD/Memory.
Where do I start? Is there a flow chart of what to do to compress and uncompress? Is it too complicated for this type of project?
A good book that steps through all the steps to take or ...