Note that there are some explanatory texts on larger screens.

plurals
  1. POstruct definition inside main() causing Segmentation Fault
    primarykey
    data
    text
    <p>Is it not possible to define structure inside main() . I tried the following only to get a Segmentation Fault:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;unistd.h&gt; #include &lt;strings.h&gt; #define TRUE 1 void main(int argc,char **argv) { struct test_struct { char test_name[50]; char summary_desc[200]; char result[50]; }; struct suite_struct { char suite_name[50]; struct test_struct test[500]; int test_count; int passed; int failed; int unresolved; int notrun; }suite[500]; int a,b; for (a=0;a&lt;500;a++) { strcpy(suite[a].suite_name,""); for (b=0;b&lt;500;b++) { strcpy(suite[a].test[b].test_name,""); strcpy(suite[a].test[b].summary_desc,""); strcpy(suite[a].test[b].result,""); } suite[a].test_count=0; suite[a].passed=0; suite[a].failed=0; suite[a].unresolved=0; suite[a].notrun=0; } } </code></pre> <p>But the moment I take the struct definition outside it works:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;unistd.h&gt; #include &lt;strings.h&gt; #define TRUE 1 struct test_struct { char test_name[50]; char summary_desc[200]; char result[50]; }; struct suite_struct { char suite_name[50]; struct test_struct test[500]; int test_count; int passed; int failed; int unresolved; int notrun; }suite[500]; void main(int argc,char **argv) { int a,b; for (a=0;a&lt;500;a++) { strcpy(suite[a].suite_name,""); for (b=0;b&lt;500;b++) { strcpy(suite[a].test[b].test_name,""); strcpy(suite[a].test[b].summary_desc,""); strcpy(suite[a].test[b].result,""); } suite[a].test_count=0; suite[a].passed=0; suite[a].failed=0; suite[a].unresolved=0; suite[a].notrun=0; } } </code></pre> <p>Not sure why this is happening. I am using the Solaris SunStudio compiler for this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload