Может кто-нибудь дать подсказку с этими ошибками от g cc? - PullRequest
0 голосов
/ 17 марта 2020

У меня есть этот код:

#include <stdlib.h>
#include <string.h>
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
#include <libavformat/avformat.h>

int main(int argc, char **argv)
{
    avcodec_register_all();
    av_register_all();

    struct AVCodecTag * const *avctag;
    AVOutputFormat *outputFormat = NULL;

    const char *file = "file.mp4";
    outputFormat = av_guess_format(0, file, 0);

    if( ! outputFormat)
    {
        printf ("No container found\n");
        exit (1);
    }
    printf("%s %d\n",outputFormat->long_name,outputFormat->video_codec);

    avctag = outputFormat->codec_tag[0];
    printf("%d\n",avctag->id);
}

Компилятор выдает эту странную ошибку, хотя я использовал -> в строке printf:

error: ‘*avctag’ is a pointer; did you mean to use ‘->’?
  printf("%d\n",avctag->id);

Но он также выдает предупреждение :

warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  avctag = outputFormat->codec_tag;

AVOutputFormat: codec_tag определяется в соответствии с документами как:

struct AVCodecTag * const *

Это точно так, как я определил указатель выше. Может кто-нибудь подсказать мне, почему я получаю предупреждение и ошибку?

Большое спасибо

Ответы [ 2 ]

1 голос
/ 17 марта 2020

В вашем объявлении слишком много *.

outputFormat->codec_tag равно struct AVCodecTag * const *, что означает, что outputFormat->codec_tag[0] это просто struct AVCodecTag const *

или альтернатива, которую вы могли бы делать

avctag = outputFormat->codec_tag;
printf("%d\n",avctag[0]->id);
1 голос
/ 17 марта 2020

Указатель avctag объявлен, как указатель на постоянный указатель

struct AVCodecTag * const *avctag;

Так что это утверждение

printf("%d\n",avctag->id);

недопустимо.

И вам нужно проверить тип выражения правой руки в этом операторе

avctag = outputFormat->codec_tag[0];

Какой тип outputFormat->codec_tag[0]?

...