2 bytes allocated problems

2010-02-24 Thread Andrey Zonov
Hi, When I try allocated pointer to a pointer, and in it some pointers (important: size is 2 bytes), the pointers lose their boundaries. Why it can happen? Test program in attach. PS in freebsd < 7, it's ok, in Linux too. -- Andrey Zonov alloc.c Description: Binary data _

Re: 2 bytes allocated problems

2010-02-24 Thread Max Laier
On Wednesday 24 February 2010 14:44:35 Andrey Zonov wrote: > Hi, > > When I try allocated pointer to a pointer, and in it some pointers > (important: size is 2 bytes), the pointers lose their boundaries. > Why it can happen? > > Test program in attach. Your test program is broken: >#define S1 "

Re: 2 bytes allocated problems

2010-02-24 Thread Dag-Erling Smørgrav
Andrey Zonov writes: > When I try allocated pointer to a pointer, and in it some pointers > (important: size is 2 bytes), the pointers lose their boundaries. Pointers have no boundareis in C. > PS in freebsd < 7, it's ok, in Linux too. Only by accident. DES -- Dag-Erling Smørgrav - d...@des.n

Re: 2 bytes allocated problems

2010-02-24 Thread Andrey Zonov
And how free() finds that the need to release? Dag-Erling Smørgrav пишет: Andrey Zonov writes: When I try allocated pointer to a pointer, and in it some pointers (important: size is 2 bytes), the pointers lose their boundaries. Pointers have no boundareis in C. PS in freebsd < 7

Re: 2 bytes allocated problems

2010-02-24 Thread Dag-Erling Smørgrav
Andrey Zonov writes: > Dag-Erling Smørgrav writes: > > Pointers have no boundareis in C. > And how free() finds that the need to release? That is a very simple question with a very complicated answer. Whole books have been written about the subject. Normally, I'd say "look it up on Wikipedia",

Re: 2 bytes allocated problems

2010-02-25 Thread Matthias Andree
Am 24.02.2010, 20:55 Uhr, schrieb Dag-Erling Smørgrav : Why is there a 0 after the 'i'? Because when you write "abcdefghi", the compiler actually stores "abcdefghi\0". That's the definition of "string" in C: a sequence of characters immediately followed by a 0. If you don't want the 0 there,

Re: 2 bytes allocated problems

2010-02-25 Thread Dag-Erling Smørgrav
"Matthias Andree" writes: > Dag-Erling Smørgrav writes: > > char a[9] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' }; > char a[9] = "abcdefghi"; > > suffices. The compiler knows there isn't room for the terminal '\0' > and omits it. Some compilers (gcc at least) warn about it. DES -- Dag-Er

Re: 2 bytes allocated problems

2010-02-25 Thread Max Laier
On Thursday 25 February 2010 23:46:03 Dag-Erling Smørgrav wrote: > "Matthias Andree" writes: > > Dag-Erling Smørgrav writes: > > > char a[9] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' }; > > > > char a[9] = "abcdefghi"; > > > > suffices. The compiler knows there isn't room for the terminal '