ما معنى هذا التحذير من الشظية وماذا يمكن أن أفعل خطأ؟

StackOverflow https://stackoverflow.com/questions/3655566

  •  01-10-2019
  •  | 
  •  

سؤال

هذا هو سطر الكود:

bool cpfs_utimens(struct Cpfs *, char const *path, struct timespec const[2]);

يعمل تشغيل الشظية 3.1.2 يولد هذا التحذير:

cpfs.h:21:74: Function parameter times declared as manifest array (size
                 constant is meaningless)
  A formal parameter is declared as an array with size.  The size of the array
  is ignored in this context, since the array formal parameter is treated as a
  pointer. (Use -fixedformalarray to inhibit warning)

تسمية المعلمة لا فرق.

هل كانت مفيدة؟

المحلول

هذا يعني أنه عندما تعلن المعلمة struct timespec const[2], ، ال 2 بين ال [ و ] غير مطلوب. تغيير الكود الخاص بك إلى:

bool cpfs_utimens(struct Cpfs *, char const *path, struct timespec const[]);

في C/C ++ ، لا يمكنك طلب مجموعة من حجم معين كمعلمة ، لأن الصفيف يعامل مثل المؤشر والمؤشرات ليس لها أحجام.

نصائح أخرى

في C99 (منذ استخدامك bool) لديك إمكانية أن تتطلب الحد الأدنى من طول صفيف المعلمة عن طريق إضافة static مثله

bool cpfs_utimens(struct Cpfs *, char const *path, struct timespec const[static 2]);

التوقيع (إذا كان هناك شيء من هذا القبيل في C) لا يزال هو معلمة المؤشر ، الفكر.

(وأيضًا لا أعرف أي مترجم حالي يقوم بشيء معقول من تلك المعلومات ، حتى الآن.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top