Author Topic: long signed int vs. int16_t  (Read 6611 times)

0 Members and 1 Guest are viewing this topic.

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
long signed int vs. int16_t
« on: August 14, 2009, 02:54:21 PM »
I'm following Webbots new tutorial:
http://www.societyofrobots.com/member_tutorials/node/341

and using his WebbotLib.

My code starts off like this:
Code: [Select]
#include "sys/axon.h"
#include "servoPWM.h"
#include "a2d.h"

//user includes
#include "kinematics.c" //SoR Biped Engine

// Define sensors
#define gyro_X ADC_NUMBER_TO_CHANNEL(0)
#define gyro_Y ADC_NUMBER_TO_CHANNEL(1)

//snip

And in kinematics.c, it starts off with this:
Code: [Select]
//initialize variables
int16_t r1L;
int16_t r2L;
int16_t r4L;
//snip

But that gives me this error:
Quote
../kinematics.c:24: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'r1L'
../kinematics.c:25: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'r2L'
../kinematics.c:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'r4L'

But if I change it to:
Code: [Select]
//initialize variables
long signed int r1L;
long signed int r2L;
long signed int r4L;
then the error goes away . . .

This is happening to all my variables . . . Whats up?

In the manual, I see:
Code: [Select]
uint16_t counter;so something else is up . . .

Offline guncha

  • Jr. Member
  • **
  • Posts: 40
  • Helpful? 0
Re: long signed int vs. int16_t
« Reply #1 on: August 15, 2009, 11:12:13 AM »
Your compiler simply does not know what "int16_t" means, the reason being that either your code or Webbot's doesn't:
Code: [Select]
#include <stdint.h>
These (u)intXX_t datatypes are easier to understand and help porting code to different compilers (not that it matters when coding for AVR). Apart from that there is no difference on which one you use.

edit: removed some bad advice :)
« Last Edit: August 15, 2009, 11:16:44 AM by guncha »

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: long signed int vs. int16_t
« Reply #2 on: August 17, 2009, 09:56:13 AM »
Problem fixed. Use .h files!

An email from Webbot's phone, whose home internet connection isn't working . . .

Quote
Try renaming kinematics.c to kinematics.h and then including this h file rather than the c file.

Its not good practice to include another C file. The effects are probably undefined and in this case it 'forgets' all the includes from your main file and so 'int16_t' etc are no longer defined and hence the compile error. If its a 'h' file then all is ok
Nb this is a compiler issue/feature not my lib

 


Get Your Ad Here