POV-Ray : Newsgroups : povray.off-topic : Tell me it isn't so! : Re: Tell me it isn't C Server Time
9 Oct 2024 13:13:39 EDT (-0400)
  Re: Tell me it isn't C  
From: Darren New
Date: 22 Jul 2009 13:55:49
Message: <4a6752a5$1@news.povray.org>
Warp wrote:
> For instance, sizeof(table) is not the same as sizeof(int*). 

Yes, OK.

> Also, you can't make 'table' "point" to
> somewhere else (because it's not a pointer).

I thought "table" was essentially a constant pointer to the first element. I 
forgot about the sizeof() bit.  I.e., that "int table[10]" made table be a 
constant pointer to the first element of an anonymous block ten integers in 
size.

>   Here 'table' is also *not* a pointer, it's an array. Now you can allocate
> instances of that struct with malloc() and you will effectively have a
> heap-allocated array.

int* table = malloc(10*sizeof(int));
creates an anonymous array, then sets "table" as a pointer to the start of 
it. So you can have heap-allocated arrays, you just can't give them names. :-)

Now we're picking nits, tho.  You're right, C does have arrays.

-- 
   Darren New, San Diego CA, USA (PST)
   "We'd like you to back-port all the changes in 2.0
    back to version 1.0."
   "We've done that already. We call it 2.0."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.