B
bwaichu
I am starting this thread after having run into two separate
programming problems,
where the compiler offered no help. The compiler did not even warn.
The programs
compiled fine. And the programs even appeared to work.
The first case was passing directly a variable of type char **.
Here's an example:
prototype: void func(char **);
WRONG
char **var;
func(var);
CORRECT
char *var;
func(&var);
The problem with the above is that the pointer is never initialized.
The second problem I ran into was typecasting an integer to a pointer.
For example:
int var;
foo((void *)var);
The above causes a problem since a pointer and an integer are two
really different types of variables. The problem is that function
required a pointer to be passed, but I needed to work with an integer
in the function I was calling.
Here's the correct way to pass the variable:
foo(&var);
to access the integer
foo(*(int *)var);
Please add additional problems, where the compiler will just compile
without warning or add some clarification to the above examples and
explanations. I prefer to write good code versus code that just works.
programming problems,
where the compiler offered no help. The compiler did not even warn.
The programs
compiled fine. And the programs even appeared to work.
The first case was passing directly a variable of type char **.
Here's an example:
prototype: void func(char **);
WRONG
char **var;
func(var);
CORRECT
char *var;
func(&var);
The problem with the above is that the pointer is never initialized.
The second problem I ran into was typecasting an integer to a pointer.
For example:
int var;
foo((void *)var);
The above causes a problem since a pointer and an integer are two
really different types of variables. The problem is that function
required a pointer to be passed, but I needed to work with an integer
in the function I was calling.
Here's the correct way to pass the variable:
foo(&var);
to access the integer
foo(*(int *)var);
Please add additional problems, where the compiler will just compile
without warning or add some clarification to the above examples and
explanations. I prefer to write good code versus code that just works.