I am a retard (perhaps a simple problem??) 
Author Message
 I am a retard (perhaps a simple problem??)

Ok I am having a problem I can't seem to find much help on.
I have a function with a header like follows

drawArray(void *arr)

This function takes the array arr (which I want to limit to double or
long). Now where I get a problem is this function is called at run
time in the de{*filter*} througth a custom button, i.e. when the user is
debugging he/she selects a varable (hopefully an array of the suported
type) and it displays it graphically. However as I have no control
over what the user selects I want to check and return an error message
if it is not valid input e.g if arr is just a double not a (double *)
I want to return an error. How do I check for this. Also is there
anyway to tell the type of a void *? At the moment I rely on the user
telling me this information.

Thanks for any help in advance



Mon, 03 May 2004 21:31:24 GMT  
 I am a retard (perhaps a simple problem??)


Quote:
> Ok I am having a problem I can't seem to find much help on.
> I have a function with a header like follows

> drawArray(void *arr)

> This function takes the array arr (which I want to limit to double or
> long). Now where I get a problem is this function is called at run
> time in the de{*filter*} througth a custom button, i.e. when the user is
> debugging he/she selects a varable (hopefully an array of the suported
> type) and it displays it graphically.

(Note the properties of this "de{*filter*}" are off-topic here. You may find
that an appropriate newsgroup for discussing it exists, in which case
posting there will get you better, or at least different, answers.)

How does `drawArray` know how many elements the presumed array has?

Quote:
> However as I have no control
> over what the user selects I want to check and return an error message
> if it is not valid input e.g if arr is just a double not a (double *)
> I want to return an error. How do I check for this. Also is there
> anyway to tell the type of a void *? At the moment I rely on the user
> telling me this information.

There's no way to tell using ISO C.

None. Zilch. Empty. Nil. Absent.

Given only a void* value, there's no portable way to find out what
it points to, or how big it is.

--
Chris "thesaurus, but not Fanthorpe" Dollin
C FAQs at: http://www.*-*-*.com/



Mon, 03 May 2004 21:49:47 GMT  
 I am a retard (perhaps a simple problem??)


Quote:
> Ok I am having a problem I can't seem to find much help on.
> I have a function with a header like follows

> drawArray(void *arr)

Sounds very poor. There is no indication about the type or the size of the
array. And what is the returned type? Could be int in pre-C99, but today's
rules have changed. You must specify the return type explicitely.

Quote:
> This function takes the array arr (which I want to limit to double or

I suppose you mean that it can has 2 types: double and long. How is the
function supposed to know it?

Quote:
> long). Now where I get a problem is this function is called at run
> time in the de{*filter*} througth a custom button, i.e. when the user is

I don't know what a custom button is. Say an event...

Quote:
> debugging he/she selects a varable (hopefully an array of the suported
> type) and it displays it graphically. However as I have no control

Should be controlled... How can you process an array with unknown size?

Quote:
> over what the user selects I want to check and return an error message
> if it is not valid input e.g if arr is just a double not a (double *)
> I want to return an error. How do I check for this. Also is there

The value returned by the function is often used for that purpose. Use an
int for example, and define some values (say 0=OK 1=err etc. You can be
more precise).

Quote:
> anyway to tell the type of a void *? At the moment I rely on the user
> telling me this information.

You can pass more information to the function. I suggest you also add the
number of elements:

typedef enum {DOUBLE, LONG} type_t;

drawArray (void *arr, size_t nb_elem, type_t type)

--
-ed-
.sig under repair



Mon, 03 May 2004 21:54:21 GMT  
 I am a retard (perhaps a simple problem??)

Quote:
>Ok I am having a problem I can't seem to find much help on.
>I have a function with a header like follows

>drawArray(void *arr)

>This function takes the array arr (which I want to limit to double or
>long). Now where I get a problem is this function is called at run
>time in the de{*filter*} througth a custom button, i.e. when the user is
>debugging he/she selects a varable (hopefully an array of the suported
>type) and it displays it graphically. However as I have no control
>over what the user selects I want to check and return an error message
>if it is not valid input e.g if arr is just a double not a (double *)
>I want to return an error. How do I check for this. Also is there
>anyway to tell the type of a void *? At the moment I rely on the user
>telling me this information.

You'll need to specify at least two other arguments for drawArray, if you
want to be able to do anything useful with it: the number of elements in
arr, and the type of each element.

--
Hong Ooi                    | Centre for Maths and its Applications

Ph: (02) 6267 4140          | ACT 0200 Australia



Mon, 03 May 2004 22:09:01 GMT  
 I am a retard (perhaps a simple problem??)
Ok I have fixed this problem.
It is kind of a complex solution so I will not write it all here. I
did not emphasise some of the issues in my question that were stopping
a more simple approach. If any one really cares what I did write to me
and I will tell ya, otherwise I can't be bothered.  :)


Wed, 05 May 2004 03:19:44 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Yes, I am retarded.

2. a very simple problem about # include files but i am a beginer

3. simple question, but I am stuck.

4. Simple Question I am sure !!!!!

5. a retarded question

6. C for the mentally retarded!

7. Bedeviled Retard Seeks Ingenious Angels

8. Help SQL server and MFC, I feel retarded!

9. Simple problem across processes - need simplest answer

10. Simple ATL Com object problem on simplest examples

11. I am new to programming and am lost

12. Perhaps it's time the C community *did* something about b

 

 
Powered by phpBB® Forum Software