Skip to main content
Senior
March 26, 2024
Solved

getting error at build as subscripted value is neither array nor pointer nor vector

Hi,

Before I start, please note that I am not sure if I am asking the question in the right place, so please feel free to direct me. 

I have written an application that can be found here.

I get build log as in below.

I have many issues, out of which, I especially want to fix "subscripted value is neither array nor pointer nor vector" issue.

Can anyone please guide me ?

Thanks.

 

22:35:30 **** Incremental Build of configuration Debug for project PCA9685 ****
make -j8 all 
arm-none-eabi-gcc "../Core/Src/PCA9685.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F407xx -c -I../Core/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/PCA9685.d" -MT"Core/Src/PCA9685.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/PCA9685.o"
In file included from ../Core/Src/PCA9685.c:9:
../Core/Inc/PCA9685.h:26:9: note: '#pragma message: i2c buffer length not defined - using default value of 32, which may not be correct for your microcontroller. Check stm32f4xx_hal_i2c.h (or similar) for your hardware and manually define BUFFER_LENGTH or I2C_BUFFER_LENGTH to remove this warning.'
 26 | #pragma message( "i2c buffer length not defined - using default value of 32, which may not be correct for your microcontroller. Check stm32f4xx_hal_i2c.h (or similar) for your hardware and manually define BUFFER_LENGTH or I2C_BUFFER_LENGTH to remove this warning.")
 | ^~~~~~~
../Core/Src/PCA9685.c: In function 'resetDevices':
../Core/Src/PCA9685.c:131:1: warning: implicit declaration of function 'MX_I2C1_Init'; did you mean 'HAL_I2C_Init'? [-Wimplicit-function-declaration]
 131 | MX_I2C1_Init();
 | ^~~~~~~~~~~~
 | HAL_I2C_Init
../Core/Src/PCA9685.c: In function 'i2cWire_beginTransmission':
../Core/Src/PCA9685.c:835:13: error: 'I2C_HandleTypeDef' has no member named 'beginTransmission'
 835 | _i2cWire->beginTransmission(addr);
 | ^~
../Core/Src/PCA9685.c: In function 'i2cWire_endTransmission':
../Core/Src/PCA9685.c:843:37: error: 'I2C_HandleTypeDef' has no member named 'endTransmission'
 843 | return (_lastI2CError = _i2cWire->endTransmission());
 | ^~
../Core/Src/PCA9685.c: In function 'i2cWire_requestFrom':
../Core/Src/PCA9685.c:852:20: error: 'I2C_HandleTypeDef' has no member named 'requestFrom'
 852 | return _i2cWire->requestFrom(addr, (size_t)len);
 | ^~
../Core/Src/PCA9685.c: At top level:
../Core/Src/PCA9685.c:859:9: error: conflicting types for 'i2cWire_write'; have 'uint8_t(uint8_t)' {aka 'unsigned char(unsigned char)'}
 859 | uint8_t i2cWire_write(uint8_t data) {
 | ^~~~~~~~~~~~~
In file included from ../Core/Src/PCA9685.c:9:
../Core/Inc/PCA9685.h:232:15: note: previous declaration of 'i2cWire_write' with type 'size_t(uint8_t)' {aka 'unsigned int(unsigned char)'}
 232 | size_t i2cWire_write(uint8_t);
 | ^~~~~~~~~~~~~
../Core/Src/PCA9685.c: In function 'i2cWire_write':
../Core/Src/PCA9685.c:861:20: error: 'I2C_HandleTypeDef' has no member named 'write'
 861 | return _i2cWire->write(data);
 | ^~
../Core/Src/PCA9685.c: In function 'i2cWire_read':
../Core/Src/PCA9685.c:870:30: error: 'I2C_HandleTypeDef' has no member named 'read'
 870 | return (uint8_t)(_i2cWire->read() & 0xFF);
 | ^~
../Core/Src/PCA9685.c: At top level:
../Core/Src/PCA9685.c:1041:1: warning: data definition has no type or storage class
 1041 | _coeff=NULL;
 | ^~~~~~
../Core/Src/PCA9685.c:1041:1: warning: type defaults to 'int' in declaration of '_coeff' [-Wimplicit-int]
../Core/Src/PCA9685.c:1041:1: error: conflicting types for '_coeff'; have 'int'
In file included from ../Core/Src/PCA9685.c:9:
../Core/Inc/PCA9685.h:252:23: note: previous declaration of '_coeff' with type 'float *'
 252 | float *_coeff; // a,b,c,d coefficient values
 | ^~~~~~
../Core/Src/PCA9685.c:1041:8: warning: initialization of 'int' from 'void *' makes integer from pointer without a cast [-Wint-conversion]
 1041 | _coeff=NULL;
 | ^~~~
../Core/Src/PCA9685.c:1042:1: warning: data definition has no type or storage class
 1042 | _isCSpline=false;
 | ^~~~~~~~~~
../Core/Src/PCA9685.c:1042:1: warning: type defaults to 'int' in declaration of '_isCSpline' [-Wimplicit-int]
../Core/Src/PCA9685.c:1042:1: error: conflicting types for '_isCSpline'; have 'int'
In file included from ../Core/Src/PCA9685.c:9:
../Core/Inc/PCA9685.h:253:21: note: previous declaration of '_isCSpline' with type '_Bool'
 253 | bool _isCSpline; // Cubic spline tracking, for _coeff length
 | ^~~~~~~~~~
../Core/Src/PCA9685.c:1044:1: warning: return type defaults to 'int' [-Wimplicit-int]
 1044 | PCA9685_ServoEval_1(uint16_t minPWMAmount, uint16_t maxPWMAmount)
 | ^~~~~~~~~~~~~~~~~~~
../Core/Src/PCA9685.c:1044:1: warning: conflicting types for 'PCA9685_ServoEval_1'
In file included from ../Core/Src/PCA9685.c:9:
../Core/Inc/PCA9685.h:239:17: note: previous declaration of 'PCA9685_ServoEval_1' with type 'void(uint16_t, uint16_t)' {aka 'void(short unsigned int, short unsigned int)'}
 239 | void PCA9685_ServoEval_1(uint16_t minPWMAmount, uint16_t maxPWMAmount);
 | ^~~~~~~~~~~~~~~~~~~
../Core/Src/PCA9685.c: In function 'PCA9685_ServoEval_1':
../Core/Src/PCA9685.c:1056:22: warning: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
 1056 | _coeff = (float*)malloc(2 * sizeof(float));
 | ^~~~~~
../Core/Src/PCA9685.c:14:1: note: include '<stdlib.h>' or provide a declaration of 'malloc'
 13 | #include "main.h"
 +++ |+#include <stdlib.h>
 14 | 
../Core/Src/PCA9685.c:1056:22: warning: incompatible implicit declaration of built-in function 'malloc' [-Wbuiltin-declaration-mismatch]
 1056 | _coeff = (float*)malloc(2 * sizeof(float));
 | ^~~~~~
../Core/Src/PCA9685.c:1056:22: note: include '<stdlib.h>' or provide a declaration of 'malloc'
../Core/Src/PCA9685.c:1056:12: warning: assignment to 'int' from 'float *' makes integer from pointer without a cast [-Wint-conversion]
 1056 | _coeff = (float*)malloc(2 * sizeof(float));
 | ^
../Core/Src/PCA9685.c:1059:11: error: subscripted value is neither array nor pointer nor vector
 1059 | _coeff[0] = minPWMAmount;
 | ^
../Core/Src/PCA9685.c:1060:11: error: subscripted value is neither array nor pointer nor vector
 1060 | _coeff[1] = (maxPWMAmount - minPWMAmount) / 180.0f;
 | ^
../Core/Src/PCA9685.c: At top level:
../Core/Src/PCA9685.c:1064:1: warning: data definition has no type or storage class
 1064 | _coeff=NULL;
 | ^~~~~~
../Core/Src/PCA9685.c:1064:1: warning: type defaults to 'int' in declaration of '_coeff' [-Wimplicit-int]
../Core/Src/PCA9685.c:1064:1: error: conflicting types for '_coeff'; have 'int'
In file included from ../Core/Src/PCA9685.c:9:
../Core/Inc/PCA9685.h:252:23: note: previous declaration of '_coeff' with type 'float *'
 252 | float *_coeff; // a,b,c,d coefficient values
 | ^~~~~~
../Core/Src/PCA9685.c:1064:8: warning: initialization of 'int' from 'void *' makes integer from pointer without a cast [-Wint-conversion]
 1064 | _coeff=NULL;
 | ^~~~
../Core/Src/PCA9685.c:1065:1: warning: data definition has no type or storage class
 1065 | _isCSpline=false;
 | ^~~~~~~~~~
../Core/Src/PCA9685.c:1065:1: warning: type defaults to 'int' in declaration of '_isCSpline' [-Wimplicit-int]
../Core/Src/PCA9685.c:1065:1: error: conflicting types for '_isCSpline'; have 'int'
In file included from ../Core/Src/PCA9685.c:9:
../Core/Inc/PCA9685.h:253:21: note: previous declaration of '_isCSpline' with type '_Bool'
 253 | bool _isCSpline; // Cubic spline tracking, for _coeff length
 | ^~~~~~~~~~
../Core/Src/PCA9685.c: In function 'PCA9685_ServoEval_2':
../Core/Src/PCA9685.c:1089:26: warning: incompatible implicit declaration of built-in function 'malloc' [-Wbuiltin-declaration-mismatch]
 1089 | _coeff = (float*)malloc(8 * sizeof(float));
 | ^~~~~~
../Core/Src/PCA9685.c:1089:26: note: include '<stdlib.h>' or provide a declaration of 'malloc'
../Core/Src/PCA9685.c:1089:16: warning: assignment to 'int' from 'float *' makes integer from pointer without a cast [-Wint-conversion]
 1089 | _coeff = (float*)malloc(8 * sizeof(float));
 | ^
../Core/Src/PCA9685.c:1119:19: error: subscripted value is neither array nor pointer nor vector
 1119 | _coeff[4 * i + 0] = y[i]; // a
 | ^
../Core/Src/PCA9685.c:1120:19: error: subscripted value is neither array nor pointer nor vector
 1120 | _coeff[4 * i + 1] = b[i]; // b
 | ^
../Core/Src/PCA9685.c:1121:19: error: subscripted value is neither array nor pointer nor vector
 1121 | _coeff[4 * i + 2] = c[i]; // c
 | ^
../Core/Src/PCA9685.c:1122:19: error: subscripted value is neither array nor pointer nor vector
 1122 | _coeff[4 * i + 3] = d[i]; // d
 | ^
../Core/Src/PCA9685.c:1126:27: warning: incompatible implicit declaration of built-in function 'malloc' [-Wbuiltin-declaration-mismatch]
 1126 | _coeff = (float*)malloc(2 * sizeof(float));
 | ^~~~~~
../Core/Src/PCA9685.c:1126:27: note: include '<stdlib.h>' or provide a declaration of 'malloc'
../Core/Src/PCA9685.c:1126:17: warning: assignment to 'int' from 'float *' makes integer from pointer without a cast [-Wint-conversion]
 1126 | _coeff = (float*)malloc(2 * sizeof(float));
 | ^
../Core/Src/PCA9685.c:1129:15: error: subscripted value is neither array nor pointer nor vector
 1129 | _coeff[0] = minPWMAmount;
 | ^
../Core/Src/PCA9685.c:1130:15: error: subscripted value is neither array nor pointer nor vector
 1130 | _coeff[1] = (maxPWMAmount - minPWMAmount) / 180.0f;
 | ^
../Core/Src/PCA9685.c: In function 'pwmForAngle':
../Core/Src/PCA9685.c:1136:13: warning: implicit declaration of function 'constrain' [-Wimplicit-function-declaration]
 1136 | angle = constrain(angle + 90, 0, 180);
 | ^~~~~~~~~
../Core/Src/PCA9685.c:1139:24: error: subscripted value is neither array nor pointer nor vector
 1139 | retVal = _coeff[0] + (_coeff[1] * angle);
 | ^
../Core/Src/PCA9685.c:1139:37: error: subscripted value is neither array nor pointer nor vector
 1139 | retVal = _coeff[0] + (_coeff[1] * angle);
 | ^
../Core/Src/PCA9685.c:1143:28: error: subscripted value is neither array nor pointer nor vector
 1143 | retVal = _coeff[0] + (_coeff[1] * angle) + (_coeff[2] * angle * angle) + (_coeff[3] * angle * angle * angle);
 | ^
../Core/Src/PCA9685.c:1143:41: error: subscripted value is neither array nor pointer nor vector
 1143 | retVal = _coeff[0] + (_coeff[1] * angle) + (_coeff[2] * angle * angle) + (_coeff[3] * angle * angle * angle);
 | ^
../Core/Src/PCA9685.c:1143:63: error: subscripted value is neither array nor pointer nor vector
 1143 | retVal = _coeff[0] + (_coeff[1] * angle) + (_coeff[2] * angle * angle) + (_coeff[3] * angle * angle * angle);
 | ^
../Core/Src/PCA9685.c:1143:93: error: subscripted value is neither array nor pointer nor vector
 1143 | retVal = _coeff[0] + (_coeff[1] * angle) + (_coeff[2] * angle * angle) + (_coeff[3] * angle * angle * angle);
 | ^
../Core/Src/PCA9685.c:1147:28: error: subscripted value is neither array nor pointer nor vector
 1147 | retVal = _coeff[4] + (_coeff[5] * angle) + (_coeff[6] * angle * angle) + (_coeff[7] * angle * angle * angle);
 | ^
../Core/Src/PCA9685.c:1147:41: error: subscripted value is neither array nor pointer nor vector
 1147 | retVal = _coeff[4] + (_coeff[5] * angle) + (_coeff[6] * angle * angle) + (_coeff[7] * angle * angle * angle);
 | ^
../Core/Src/PCA9685.c:1147:63: error: subscripted value is neither array nor pointer nor vector
 1147 | retVal = _coeff[4] + (_coeff[5] * angle) + (_coeff[6] * angle * angle) + (_coeff[7] * angle * angle * angle);
 | ^
../Core/Src/PCA9685.c:1147:93: error: subscripted value is neither array nor pointer nor vector
 1147 | retVal = _coeff[4] + (_coeff[5] * angle) + (_coeff[6] * angle * angle) + (_coeff[7] * angle * angle * angle);
 | ^
../Core/Src/PCA9685.c: In function 'i2cWire_endTransmission':
../Core/Src/PCA9685.c:848:1: warning: control reaches end of non-void function [-Wreturn-type]
 848 | }
 | ^
../Core/Src/PCA9685.c: In function 'i2cWire_requestFrom':
../Core/Src/PCA9685.c:857:1: warning: control reaches end of non-void function [-Wreturn-type]
 857 | }
 | ^
../Core/Src/PCA9685.c: In function 'i2cWire_write':
../Core/Src/PCA9685.c:865:1: warning: control reaches end of non-void function [-Wreturn-type]
 865 | }
 | ^
../Core/Src/PCA9685.c: In function 'i2cWire_read':
../Core/Src/PCA9685.c:881:1: warning: control reaches end of non-void function [-Wreturn-type]
 881 | }
 | ^
make: *** [Core/Src/subdir.mk:37: Core/Src/PCA9685.o] Error 1
"make -j8 all" terminated with exit code 2. Build might be incomplete.

22:35:33 Build Failed. 29 errors, 25 warnings. (took 2s.371ms)
This topic has been closed for replies.
Andrew Neil
Andrew NeilBest answer
Super User
March 27, 2024

You need to read the message literally - it is telling you what is wrong, and where.

When it says "../Core/Src/PCA9685.c:1041:1", that means

  • ../Core/Src/PCA9685.c is the name of the file;
  • :1041 is the line number within that file;
  • :1 is the character position (or columns) along that line;

So it's telling you that you have two different declarations of _coeff:

  1. In ../Core/Src/PCA9685.c at line 1041 you have it as 'int'
  2. In ../Core/Inc/PCA9685.h at line 252 you have it as 'float *'

The same variable  - _coeff - cannot have 2 different types; it cannot be both  'int' and 'float *'

 

#FileLineColumn

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.

5 replies

Tesla DeLorean
Guru
March 26, 2024

Errors tend to compound, start with the first ones.

The github isn't public.

Earlier in the code it thinks _coeff is an integer, not a float* pointer.

Other places you are using functions in defined in main() which you've not proto-typed in pca9685.c

Put proto-types and extern definitions in main.h

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
demirAuthor
Senior
March 26, 2024

Sorry, now I ve made the repo public.

Can you please check ?

Tesla DeLorean
Guru
March 26, 2024

main.c

static void MX_I2C1_Init(void); // this can't be static if you want to call it from other source files

main.h

extern I2C_HandleTypeDef hi2c1; // Allow you to reference elsewhere

extern TIM_HandleTypeDef htim1;

extern UART_HandleTypeDef huart2;

extern void MX_I2C1_Init(void); // Prototype so you can call the non-static function

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..