'sizeof'对无效类型问题的无效应用

时间:2018-09-07 02:42:02

标签: c sizeof

出现错误

invalid application of 'sizeof' to incomplete type 'TProgmemRGBGradientPalette_byte* const [] {aka const unsigned char* const []}'

第46行https://pastebin.com/xhVEnqts

下面的最后一行是第46行:

#define FASTLED_ALLOW_INTERRUPTS 0
#include "FastLED.h"
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WebSocketsClient.h> //  https://github.com/kakopappa/sinric/wiki/How-to-add-dependency-libraries
#include <ArduinoJson.h> // https://github.com/kakopappa/sinric/wiki/How-to-add-dependency-libraries
#include <StreamString.h>

#define DATA_PIN    3
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS    30       // Change this to reflect the number of LEDs you have
#define BRIGHTNESS  128       // Set Brightness here

CRGB leds[NUM_LEDS];

#define SECONDS_PER_PALETTE 15


ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
WiFiClient client;

#define MyApiKey "xxxx" // TODO: Change to your sinric API Key. Your API Key is displayed on sinric.com dashboard
#define MySSID "xxxxx" // TODO: Change to your Wifi network SSID
#define MyWifiPassword "xxxx" // TODO: Change to your Wifi network password

#define HEARTBEAT_INTERVAL 300000 // 5 Minutes

uint64_t heartbeatTimestamp = 0;
bool isConnected = false;

void setPowerStateOnServer(String deviceId, String value);
void setTargetTemperatureOnServer(String deviceId, String value, String scale);

extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
extern const uint8_t gGradientPaletteCount;

uint8_t gCurrentPaletteNumber = 0;

CRGBPalette16 gCurrentPalette( CRGB::Black);
CRGBPalette16 gTargetPalette( gGradientPalettes[0] );

const uint8_t gGradientPaletteCount =
sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPalettePtr );

2 个答案:

答案 0 :(得分:1)

它的extern变量具有未知的编译时间大小。如果找不到大小,那么代码编译器就不会如此

答案 1 :(得分:1)

如果不存在数组类型,则数组类型为不完整类型,并且sizeof无法应用于不完整类型。

以下行表示gGradientPalettes的定义存在于其他文件中。

extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];

编译器无法找到此定义,因此在此行抱怨:

const uint8_t gGradientPaletteCount =
sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPalettePtr );