R
Richard Bos
Martin Johansen said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
p is a void *. One does not need to cast void *s.
Richard
Martin Johansen said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
Martin Johansen said:Richard Bos said:Martin Johansen said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
p is a void *. One does not need to cast void *s.
Well, in this example I do, so that when array is passed as a void pointer,
then casted, the compiler can still warn me of possible access violations,
Richard Bos said:Martin Johansen said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
p is a void *. One does not need to cast void *s.
Martin said:Richard Bos said:Martin Johansen said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
p is a void *. One does not need to cast void *s.
Well, in this example I do
Jeremy said:Martin said:Richard Bos said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
p is a void *. One does not need to cast void *s.
Well, in this example I do
You can't. C only allows casts to scalar types (or void).
Array types aren't scalar.
Richard Bos said:violations,Martin Johansen said:Richard Bos said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
p is a void *. One does not need to cast void *s.
Well, in this example I do, so that when array is passed as a void pointer,
then casted, the compiler can still warn me of possible access
I fail to see what you could possibly achieve here. Perhaps you should
demonstrate what you mean with a simpler type, say an int *.
Martin Johansen said:No, the point is the array.
I could solve this problem by defining a structure with only an array inside
of the array type, it would work. But is it possible to typecast directly
back to the type I refered to?
Martin said:Richard Bos said:Martin Johansen said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
p is a void *. One does not need to cast void *s.
Well, in this example I do,
so that when array is passed as a void pointer,
then casted, the compiler can still warn me of possible access
violations, and also so I can use sizeof,
and also access the array directly. So I do
need to typecast this, but I cannot see how it can be done...
#include <stdio.h>Martin said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
Martin said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
Richard Bos said:Martin Johansen said:Say I have these variables:
char *array[2];
void *p;
how can I typecast p to the type of array?
p is a void *. One does not need to cast void *s.
Well, in this example I do, so that when array is passed as a void pointer,
then casted, the compiler can still warn me of possible access violations,
and also so I can use sizeof, and also access the array directly. So I do
need to typecast this, but I cannot see how it can be done...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.