2011/3/7-4/20 [Computer/SW/Languages/C_Cplusplus] UID:54056 Activity:nil | 3/7 I have a C question. I have the following source code in two identical
files t.c and t.cpp:
#include <stdlib.h>
int main(int argc, char *argv[]) {
const char * const * p1;
const char * * p2;
...
|
2004/12/14-15 [Computer/SW/Compilers] UID:35291 Activity:moderate | 12/14 If I have a C function like this
void foo(void) {
static const char unused1[] = "one";
const char * const unused2 = "two";
...... some code ......
return;
...
|
2004/8/10-11 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Compilers] UID:32805 Activity:high | 8/10 C question. Is there anything wrong with the following?
const my_struct_t **pp;
pp = malloc(sizeof(my_struct_t *));
pp = realloc(pp, sizeof (my_struct_t *) * 2);
"gcc -Wall" doesn't complain. But the M$ compiler (cl.exe) complains
about the realloc line:
...
|
2003/12/8-9 [Computer/SW/Languages/C_Cplusplus] UID:11356 Activity:nil | 12/8 c++ question, how do I overload << in my class so it will handle
endl? ie: myclass << "some string" << endl
I know how to do the "some string" part:
myclass & operator << (const char * s);
what about endl?
Thanks!!
...
|
2003/9/10 [Computer/SW/Languages/C_Cplusplus] UID:29529 Activity:nil | 9/10 Stupid question: how do I reference a C callback?
int mycompare(void const *a, void const *b) { ... }
qsort(msg, sizeof(Msg), numMsgs, mycompare);
I get
"Type error in argument 4 to `qsort'; calling convention mismatch."
\_ There's nothing wrong in the you reference it. However, you should
...
|
2002/7/13-15 [Computer/SW/Languages/C_Cplusplus] UID:25351 Activity:moderate | 7/13 how do i pass variables to the system in C ? e.g.
system("echo input is %s", argv[1]);
results in "input is %s" but I want the system to see argv[1]
(I know i can just use printf, but not for what i really want to do).
\_ sprintf into array, pass array to system?
\_ so write your own function that takes a variable number of
...
|
2001/9/23-24 [Computer/SW/Languages/C_Cplusplus] UID:22600 Activity:moderate | 9/23 let's say there's a C library you want to use called libmdn.so.
I think to load it you'd go something like:
static { System.loadLibrary("mdn"); }
However, let's say that a function call looked like this:
mdn_result_t mdn_encodename(int actions, const char
*from, char *to, size_t tolen)
...
|
2001/3/17-18 [Computer/SW/Languages/C_Cplusplus] UID:20827 Activity:high | 3/16 Why does so much C sample code use #define instead of const?
\_ because any good C code will use a bunch of preprocessor
anyways. you can't be a good C programmer and eschew the
preprocessor. For that, you need a language which fills those
gaps with other constructs (c++ templates go a long way to
obviate the need for preprocessor for example). you
...
|
2000/6/21-22 [Computer/SW/Languages/C_Cplusplus] UID:18506 Activity:very high | 6/20 I have a variable inside a struct. I want to be able to initialize
that variable ONCE and not write to it again. Any subsequent writes
should not be permitted. Is there a way to do that in C? I know
about "const int foo = 5;" but the value I need to pass in is dynamic
and happens at runtime. Declaring a variable as const doesn't let
me assign anything to it at all. Thanks.
...
|
|