I was asked a very interesting question during a C interview: How can you implement a function f() in such a way that it can only be called from a particular g() function. If a function other than g() tries to call f() it would result in a compiler error.
At first, I though this could be done with function pointers and I could get close...
Any recommendations for a C/C++ kd-tree?
I'm looking for an existing implementation which the poster hopefully has worked with or has heard good things about. Also, I need to use this kd-tree to do a 1/2-NN search.
...
After reading some stuff it seems I can map the SMBIOS memory and parse it.
I have no idea on how to go about this.
I can't use any managed code as I would like this to be compilable under any OS.
Does anyone have any code examples how to go about this?
...
I am using a basic C code to print to a text file:
FILE *file;
file = fopen("zach.txt", "a+"); //add text to file if exists, create file if file does not exist
fprintf(file, "%s", "This is just an example :)\n"); //writes to file
fclose(file); //close file after writing
printf("File has been written. Please review. \n");
My question...
Need help compiling in C. When using GCC at home (Windows, 3.4.5), the code compiles fine (even with -Wall). When using the uni's GCC (4.3.3, debian), I keep getting the following message - "expected ')' before '*' token". What might be the matter? (Needless to say, compiling it on school's farm is a must).
The exact error message:
Matr...
Very easy question for you Gurus but I haven't found the answer yet with about a good amount of searching.
I have some code that prints the amount of memory used by the program. The line is similar to this:
printf("The about of RAM used is %u", anIntVariable*sizeof(double) );
where anIntVariable is an int variable for the number of e...
I have aproblem with my mips port....Whenever i try to compile a C program with a printf statement it gives a warning saying it is not recognized and in the generated assemble file there is no .asciiz directive...The string is not there....can anyone please tell me why??
And also what is the difference in between building a bare metal c...
If I have the following:
/*
* example.h
*/
#ifndef EXAMPLE
#define EXAMPLE
#include <stdio.h>
extern int parse_string(FILE *, char const*, const unsigned int);
#endif
Will this mean that code that uses ... #include example.h ... won't have to ... #include example.h's ... dependencies ? ( ie: #include <stdio.h> )
...
Assuming I have to use C (no C++ or object oriented compilers) and I don't have dynamic memory allocation, what are some techniques I can use to implement a class, or a good approximation of a class? Is it always a good idea to isolate the "class" to a separate file? Assume that we can preallocate the memory by assuming a fixed number of...
I want to run a dos command from my program for example "dir" command.
I am doing it like,
system("dir");
Is there any way to read the output of that command directly into a program variable?
We can always redirect the output to a file and then read that file, by doing
system("dir > command.out");
And then reading command.out fil...
#ifndef MACROS_NULLCHECK_H_
#define MACROS_NULLCHECK_H_
#include <assert.h>
#define NULLCHECK(x) assert(x != (void *) 0);
#endif
If I used the above style as a template for declaring Macros, what provisos would you have?
...
I have a statemachine in a real-time system with very few (3) states.
typedef enum {
STATE1,
STATE2,
STATE3
} state_t;
However, the transitions between those states need considerable time and have their own subdivisions. So I have two choices, either I extend the main statemachine such that all the intermediate states are ...
Is it during a pre-processing or compilation stage, say on gcc? Is it different on other compilers?
...
Why can't it convert double *** to const double ***?
void foo(const double ***d)
{
}
int main (int args, char*[] args)
{
double ***d;
/*initialize d */
foo(d);
}
...
I am trying to optimize this sort of things in a heavy computing application:
say I have a
double d[500][500][500][500];
and the following is quite costly at least from compiler perspective
double d[x][y][j][k]
I want to tell compiler is that it's contiguous memory, to facilitate computing the offset.
In my example,
I have s...
GLibC has a method semtimedop which allows you to perform an operation (a semaphore acquire in this case) which times out after a certain amount of time. Win32 also provides WaitForSingleObject which provides similar functionalty.
As far as I can see there is no equivalent on OSX or other Unices. Can you suggest either the equivalent fo...
Hi, my code segfaults and I don't know why.
1 #include <stdio.h>
2
3 void overwrite(char str[], char x) {
4 int i;
5 for (i = 0; str[i] != '\0'; i++)
6 str[i] = x;
7 }
8
9 int main(void) {
10 char *s = "abcde";
11 char x = 'X';
12 overwrite(s, x);
13 printf("%s\n", s);
14 return 0;
15 }
The gdb ...
Looking at http://savannah.gnu.org/projects/nana/ it seems that the last work was done on Nana four years ago, and the official gnu.org homepage for nana is a placeholder. Given how inactive projects tend to suffer from bitrot:
Has the project died?
Is there a successor?
Do folks have a different assertion/logging library for C/C++ ...
How do I get and print a char from a user?
This want do it...
#include <stdio.h>
int main() {
float number1;
char mychar = ' ';
printf("Number?\n");
scanf("%f", &number1);
printf("Character?\n");
scanf("%c", &mychar);
printf("You typed number: %f\n", number1);
printf("You typed the char: %c\n", mycha...
How can you do a "Press Enter to Continue" in C?
...