To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 3745
3744  |  3746
Subject: 
RE: problems with creating arrays of larger sizes
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Tue, 18 May 2004 16:56:30 GMT
Viewed: 
5129 times
  
Andreas Jurk wrote:
OK, here is my code.

int main()
{
int i;
char c[n];

for(i=0;i<n;i++)
{
*(c+i)=0;
}
return 0;
}

This won't work for sure.

Need to understand the difference how array and pointers are being allocated
... And  char is usually one or two bytes, depending on type of procesor;
and pointer is  usually 4 bytes, unless you go to 64-bit processor ... If
you wish to utilize the convenicence of using array... Try this:

E.g.

char *c2=(char*)NULL;
char c1[10];

memset(c1, 0, 10);

OR

char *c2=(char*)NULL;
char c1[10];

c2 = c1;
// so whatever c1 points to , c2 will have the content; and vice versa

memset(c1,0, 10);
// this will do the initialization that you wish to do ;  for both c1 and
c2.

//e.g.
// the following  will print A A A A
memcpy(c1, 65, 10);
printf("%c %c %c %c\n", *(c2+0),*(c2+2), *(c2+7), *(c2+8));

// the following  will print B B B B
memcpy(c2,'B' , 10);
printf("%c %c %c %c\n", *(c1+0),*(c1+2), *(c1+7), *(c1+8));

// but beware, if you are trying deallocate c2, not only c1 is corrupted, it
may very well crash in most dll.

--
E



Message is in Reply To:
  Re: problems with creating arrays of larger sizes
 
(...) This won't work for sure. If you look into the kernel sources, DEFAULT_STACK_SIZE gives the value for every user program's stack. Actually, this is 1KByte, if I remeber it right. Your character array will be allocated on the stack and so you (...) (20 years ago, 17-May-04, to lugnet.robotics.rcx.legos)

6 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR