GCC compile, run but show "segment error" Workaround

Source: Internet
Author: User

For the first time on the Liunx (Liunx Mint 17) using GCC to compile C files, unexpectedly prompted "Can't find Stdio.h", after Google found that execution

sudo Install build-essential

Can, see: http://slipper-99933.blog.163.com/blog/static/39954044201021651833785/

Body:

? Just learned the flexible array, according to the tutorial wrote a flexible array to generate the Fibonacci sequence, after a change after the GCC compiler passed, the runtime is prompted "segment error." Google says it is most likely a memory access error caused by the array Nearúdtoúd interface. A careful examination is due to access to an unassigned pointer.
? To avoid such problems after all the definition of pointers are initialized first, but also strict attention to the pointer before the value of access.
?
? Before modification:

typedefstruct_soft_array{intLen; intarray[];} Softarray;softarray* Create_soft_array (intsize) {Softarray*ret; RET->len =size; if(Size >0 )    {       returnret = (softarray*) malloc (sizeof(*ret) +sizeof(int)*size); }    returnRET =NULL;}

? After modification:

 typedef struct   _soft_array{ int   Len;  int   array[];} Softarray;softarray  * Create_soft_array (int   size)    {softarray  * ret = NULL;  if  (Size > 0   = (softarray*) malloc (sizeof  (*ret) + sizeof  (int ) *size);    RET ->len = size;  return   ret;}  

date:2014-10-25


GCC compile, run but show "segment error" Workaround

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.