On 7/17/07, peternilsson42 <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
>
> "Ahmed Shabana" <[EMAIL PROTECTED]> wrote:
> > Subject: has this any syntax error ??
>
> Don't ask your question in the subject line. In any case,
> most compilers can answer the question for you.
OKAY , I AM SO SORRY REALLY ABOUT THIS
> Your post reaks of homework assignment to me.
NO I AM A LINUX SYS ADMIN AND I IMPROVE MY SELF BY LEARNING C
> Is there any reason you're limiting the question to
> syntax errors?
YES BECAUSE THERE IS NO COMPILATION ERRORS TAKE PLACE AND EXECUTION
ERROR MESSAGE IS "Segmentation fault "
> > #include<stdio.h>
> >
> > // My implementation of sort
>
> Syntax error under C90.
I USE GCC
> > #define LEN ( sizeof(x) / sizeof(int) )
>
> A much more robust macro is...
>
> #define countof(x) ((size_t)(sizeof(x)/sizeof*(x)))
NOT TRUE AT ALL IF U WANT TO MAKE IT TYPE INDEPENDENT , I THINK THIS
WILL BE BETTER
#define LEN ( sizeof(x) / sizeof(X[0]) )
> > main()
>
> Syntax error in C99 and C++. Try...
>
> int main(void)
>
> > {
> > int x[] = {5,3,2,7,8,9} ;
> > int index[LEN] ;
>
> int index[countof(x)];
>
> Notice how this macro works even if you one day change
> the type of x? Note also that size_t is a better index
> variable than int in most cases.
THE ABOVE REPLY IS VALID HERE ALSO
> That said, it's not clear why you defined a variable
> that you never use.
>
> > int *tmp, i, j, c = 0;
>
> Why make tmp a pointer? Writing tmp = 0 has to be easier
> to read and write than tmp = &x[0].
>
> > int *sorted[LEN] ;
> >
> > if (x[0] > x[1] )
> > tmp = &x[0] ;
> > else
> > tmp = &x[1] ;
> > for ( i = 0; i++; i = LEN-c ){
>
> Valid syntax, but garbage nonetheless.
>
> > for ( j = 0; ; j = c ){
>
> Valid syntax, but garbage nonetheless.
>
> > if ( &x[i] != sorted[j++] || c == 0 )
>
> The contents of 'sorted' are uninitialised (garbage) to begin
> with. Comparing an element with x[i] will invoke undefined
> behaviour.
>
> > if ( *tmp > x[i] )
> > ;
> > else tmp = &x[i] ;
> > }
> > sorted[LEN-c] = tmp ;
>
> If c is 0, this will tread on memory you don't own.
>
> > ++c ;
> >
> > }
> > for (i = 0; i++; i = LEN )
>
> Valid syntax, but garbage nonetheless.
>
> > printf( "%d\n",*sorted[i] );
> > }
> >
> > PLZ TRY IT YOUR SELF AND THEN ANSWER ME
>
> Funny, that's the exact thing I was going to ask you to do.
>
> --
Dear Peter
after all of this the same error still exist "Segmentation fault "