Предупреждение: Несовместимые типы указателей, присваиваемые «node_t *» (он же «struct node *») из «mode_t» (он же «unsigned int *») - PullRequest
0 голосов
/ 28 апреля 2019

Наш проект о создании фильма с использованием робота и программного обеспечения, разработанного одним из наших профессоров здесь, в нашем колледже.Библиотека называется MyroC, и роботы используют эту библиотеку для многих функций.В идеале у нас есть робот, делающий несколько кадров (картинок) пользовательских входов.У пользователя также будет возможность вставлять «сцены» или небольшие вспомогательные фильмы в основной фильм.

Я начинающий программист, изучающий язык Си.В моем последнем школьном проекте у меня и моего партнера было много проблем при работе с указателями и связными списками в C. Мы понимаем самые основные идеи назначения значений узлам в списках и смены адресов, но мы не можемкажется, выяснить, откуда приходят наши предупреждения.Мы провели поиск в различных онлайн-источниках и текстах, чтобы сравнить синтаксис нашего кода, и мы не видим, где мы можем что-то делать не так.

Вот наш код:

//This part is contained in a separate header file called "movie.h"

    struct node { /* Singly-linked list nodes contain a Picture and point to next */
      Picture frame;
      node_t * next;
    };

    typedef struct node node_t;   /* Shorthand type for nodes in the picture list */

    typedef struct {     /* Wrapper struct for the movie as a linked list */
      node_t * first;
      node_t * last;
    } movie_t;

// This part is contained in a separate file called "movie.c" 
// An appropriate reference is made to movie.h
// #include "movie.h"

    movie_t
    create (void)
    {
      movie_t movie = {NULL, NULL}; // initially create an empty movie
      return movie;
    } // movie

    size_t
    size (movie_t * movie)
    {
      unsigned int count = 0;
      node_t * current = movie->first;
      while (current != NULL) {
        count++;
        current = current->next;
      }
        return count;
    } // size

    bool
    is_empty (movie_t * movie)
    {
      if (size(movie)==0) // movie contains no frames
        return true;
      else
        return false; // movie contains frames
    } // empty


    bool
    add (movie_t * movie, Picture frame) // add a frame to the end of the movie
    {
      int before_size = size(movie);

      node_t * new_node;
      new_node = malloc(sizeof(node_t));

      if (new_node == NULL) {
        printf("Error, malloc failed.\n");
        exit(EXIT_FAILURE);
      }

      node_t * cursor = movie->first;
      while(cursor->next != NULL) {
        cursor=cursor->next;
      }
      cursor->next = new_node;
      movie->last = new_node;
      new_node->frame = frame;

      if (before_size < size(movie) && (is_empty(movie)==false))
        return true;
      else
        return false;
    } // add


    void // insert a frame before index
    insert (movie_t * movie, movie_t * scene, unsigned int index)
    {
      node_t *insertion;
      insertion = malloc(sizeof(node_t));
      if (insertion == NULL) {
        printf("Error, malloc failed.\n");
        exit(EXIT_FAILURE);
      }

      insertion = movie->first;

      for (unsigned int i = 0; i < index; i++) {
        if (insertion != NULL) 
          insertion = insertion->next;
      }
      scene->last = insertion->next;
      insertion->next = scene->first;

    } // insert

клеммные выходы

error: unknown type name 'node_t'; did you mean 'mode_t'?
node_t * next;
^~~~~~
mode_t   
/usr/include/x86_64-linux-gnu/sys/types.h:70:18: note: 'mode_t' declared here    

1 Ответ

1 голос
/ 28 апреля 2019

Ваше первое сообщение об ошибке раскрывает все. Вы используете node_t до того, как объявите его, что вы делаете под ним.

Вещи должны быть объявлены / определены до их использования.

Так двигайся ...

typedef struct node node_t;   /* Shorthand type for nodes in the picture list */

Так становится ...

typedef struct node node_t;   /* Shorthand type for nodes in the picture list */

//This part is contained in the header file "movie.h"
struct node { /* Singly-linked list nodes contain a Picture and point to next */
   Picture frame;
    node_t * next;
};
...