مشكلة / خطأ في المبتدئين مع ANSI-C و GCC تحت Ubuntu
سؤال
أنا فقط أبدأ برمجة ANSI C مع GCC تحت Ubuntu (9.04). أحصل على رسائل الخطأ التالية:
رسائل خاطئة:
main.c:6: error: expected identifier or ‘(’ before ‘/’ token
In file included from /usr/include/stdio.h:75,
from main.c:9:
/usr/include/libio.h:332: error: expected specifier-qualifier-list before ‘size_t’
/usr/include/libio.h:364: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:373: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:493: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_IO_sgetn’
In file included from main.c:9:
/usr/include/stdio.h:314: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:682: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
/usr/include/stdio.h:688: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
main.c:12: error: expected identifier or ‘(’ before ‘/’ token
أفترض أنها مشكلة بسيطة للغاية ، ربما في تكوين Ubuntu أو GCC. أنا جديد في البرمجة تحت Linux أيضًا. غوغل للحصول على المساعدة وذهبت من خلال الدورة التعليمية ولكن لم يستطع العثور على إجابة. شكرًا لك!
الشفرة:
/* cheat with the preprocessor to skip over missing lines to attempt
to duplicate the circumstance of the original code */
#line 9
// #include <some_random_header.h>
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv)
{
printf("TestOutput\n");
return (0);
}
يأمر:
~/Documents/projects/Trials$ gcc -Wall -ansi main.c
المحلول
هل أنت متأكد حقًا من أن الرمز الذي تظهره هو الرمز الذي تقوم بتجميعه بالفعل؟ تحصل على الخطأ:
main.c:12: error: expected identifier or ‘(’ before ‘/’ token
لكن الكود ليس لديه بالفعل 12 سطرًا فيه.
نصائح أخرى
لقد استخدمت "//" للتعليق على خطوط ، والتي لا تحب ANSI-C. شكرا لكم جميعا على آرائكم!
لا تنتمي إلى StackOverflow