chilli said we need to know size of the array at the compile

The Partridge Family were neither partridges nor a family. Discuss.
albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: chilli said we need to know size of the array at the com

Post by albinopapa » September 8th, 2018, 9:34 pm

Yumtard wrote:I thought using delete after new was implied
If you have to suggest using operator new or operator new[], then they probably don't know how to deallocate memory as well. You may have implied it, but that doesn't mean they know that.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

JDB
Posts: 41
Joined: August 5th, 2015, 9:50 am
Location: Australia

Re: chilli said we need to know size of the array at the com

Post by JDB » September 11th, 2018, 5:33 pm

It seems like it's actually possible to some extent in C++11 or maybe it's just the gcc compiler I'm using, but I was able to make a function like this work:

Code: Select all

void my_func(int arr_size)
{
    char myArray[arr_size];
    ...
}
I'm thinking it must automatically do memory allocation and de-allocation behind the scenes, but I don't think it would be allocating on the stack.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: chilli said we need to know size of the array at the com

Post by albinopapa » September 11th, 2018, 7:27 pm

The GCC compiler probably supports variable length arrays, which in C is a thing. In C++, I do not believe it is supported. So the GCC compiler allowing variable length arrays for C++ code would be a non-conforming extension.

Variable Length Arrays
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

JDB
Posts: 41
Joined: August 5th, 2015, 9:50 am
Location: Australia

Re: chilli said we need to know size of the array at the com

Post by JDB » September 11th, 2018, 7:58 pm

Interesting bit of knowledge, good to know why my code is working lol.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: chilli said we need to know size of the array at the com

Post by chili » September 12th, 2018, 1:17 am

I wouldn't have believed it. Usually it is microsoft who is always fucking up conformation :D
Chili

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: chilli said we need to know size of the array at the com

Post by albinopapa » September 12th, 2018, 3:26 am

chili wrote:I wouldn't have believed it. Usually it is microsoft who is always fucking up conformation :D
I figured as much, glad I was able to find something to back my claim.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply