Am 29.08.16 um 14:46 schrieb Steve D'Aprano:
On Mon, Aug 29, 2016 at 10:13 PM, BartC <b...@freeuk.com> wrote:
In C, you can write this:

 int x;

 x = 5;
 x = "hello";

Let me see if I've got this straight... Bart's second assignment will
allocate a block of memory at least five bytes in size, stuff the ASCII
codes for 'h', 'e', 'l', 'l' and 'o' in that block (possibly with a null
byte at the end?) and then assign x to the address of that block.

Am I right?

Almost - the block of memory is statically allocated, i.e. there is a block of memory reserved for "constants" that are loaded on start-up of the program. x is assigned a pointer to that string. The difference is that you are not allowed to write to this memory area, for some compilers it causes a segfault if you try to write there.

YMMV - I consider this a gross abuse of "dark corners" in C.

        Christian
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to