I'm getting compiler errors in all my function prototypes.
The error is "error: expected '=', ',', ';', 'asm' or 'attribute' before 'CALCOR".
CALCOR is the name of the function and the prototype is just the first line of the function followed by a semicolon as Ancient Dragon said in another post.
Function is "int16_t CALCOR(float &Voltage)" with a lot more code afterward.
Prototype is "int16_t CALCOR(float &Voltage);"

What comes just before the CALCOR(...) prototype and/or function defintion. Also, do you have the prototype before, or after, the function definition? And if the prototype is to be used by other translation units (.C or .CPP files) then it should be declared as "extern" as in extern int16_t CALCOR(float& Voltage);

One final thing - did you define (typedef or #define) int16_t before the function declaration (prototype or definition)?

int16_t is defined in a Microchip provided file which is included above all uses of it in headers and sources. The prototypes are defined in a file called "calibration.h" and the function is in a file called "calibration.c". That's how my books on C and C++ said to do it if I understood correctly.

what compiler are you using? Please post the contents of the *.c file where the error appears, or at least the part from line 1 until the line that contains the error.

Another hint: check calibration.h to see if it expects some macro definitions to be defined before including that file. Look for lines that begin with #ifdef or #ifndef

The compiler is XC32 v1.20 for 32 bit embedded processors from Microchip.

User Header is:

/*
 * Project:     Pulse_Generator
 * File:        user.h
 * Author:      Kent Johnstone
 * Processor:   PIC32MX575F512L
 * Compiler:    XC32 v1.20
 *
 * Created on October 17, 2013, 10:10 PM
 * This header file is for all the user functions
 */
/*  Pointer pointers
 *
 * What sepp2k said is quite correct, but difficult to understand for noobs.
 * Here is possibly a more understandable example:

    int anInt = 5;
    int* ptrToAnInt = &anInt;
    anInt += 2;
    printf("anInt and ptrToAnInt == %d (%d)\n", anInt, *ptrToAnInt);
 * This should result in the output "anInt and ptrToAnInt == 7 (7)".
 * Clear as mud yet? :-)
 */

#ifndef USER_H
#define USER_H

#ifdef  __cplusplus
extern "C" {
#endif

#include "TimeDelay.h"
#include "calibration.h"
#include "hardware_profile.h"
#include <plib.h>

// FRAM Definitions
#define MWREN    0x06                   // Write Enable
#define MWRDI    0x04                   // Write Disable
#define MRDSR    0x05                   // Read Status Register
#define MWRSR    0x01                   // Write Status Register
#define MREAD    0x03                   // Read Command
#define MWRITE   0x02                   // Write Command
#define MSLEEP   0xB9                   // Enter Sleep Mode
#define SPIMEM_MAX_ADDR 0x0003FFFF      // FRAM highest address

/* Set up variables for use in function prototypes                            */
    float Voltage_High = 0;
    float* ptrVoltage_High = &Voltage_High;
/* Function Prototypes */
// user.h
void setDAC_High(float Voltage_High);
void setDAC_Low(float Voltage_Low);
void initialize (void);
//void Set_DAC1(float DAC1);
void SPIPORT_Write(uint8_t PortBuffer[], uint8_t NumBytes);
uint32_t SPIPORT_Read(uint8_t PortBuffer[], uint8_t NumBytes);
void ClrDAC(void);
void delay_us(UINT32 us);
void ClearSPIMem(void);
void SPIMEM_WRITE(uint32_t SPIMEM_WR_ADDR, uint8_t PortBuffer[], uint8_t NumBytes);
uint32_t SPIMEM_READ(uint32_t SPIMEM_RD_ADDR, uint8_t NumBytes);
int interpolationSearch(int CalCor[], float Voltage);
int16_t CALCOR(&Voltage);               // routine to get the correction factor

void SS_RESET(void);                    // clears all SPI slave selects
void SS_FRAM(void);                     // Sets SPI slave select for FRAM
void SS_DAC1(void);                     // Sets SPI slave select to DAC1
void SS_DAC2(void);                     // Sets SPI slave select to DAC2
void RSTDAC(void);                      // Sets DACs to zero volts out
void SETDAC(void);                      // Allows DACs to be programmed
void LOADDAC(void);                     // Loads programmed data into DACs and sets them to the loaded value
void DACRDY(void);                      // Allows DACs to be programmed and loaded at the same time
void ENDACPLUS(void);                   // Turns on high voltage and off low voltage
void ENDACNEG(void);                    // Turns on low voltage and off high voltage
/*  Variables*/
//uint8_t SPIPORT;                      // Used for setting port number for all SPI transfers

uint8_t PORTAOUTPUT, SPIPORT, Port;
uint16_t CODE1, CODE2;                  // 16 bit number for programming DACs
int16_t  CalCor[27];                    // Cal Correction factor array
int16_t  CalVal;                        // Adjusted Cal Cor after interpolation
float DAC1, VOUT;
float Voltage_High=0;
float Voltage_Low=0;
float Voltage=0;
//uint8_t NumBytes;                       // Used for SPI Read and Write
uint16_t DAC1CODE, DAC2CODE;            // Actual code to send to DACs
uint8_t PortBuffer[16];

uint16_t pass = 0;                      // For clearing memory
uint32_t MADDR = 0x000000;              // Initialize memory last address
uint32_t SPIMEM_WR_ADDR = 0x000000;     // Initialize Memory write address
uint32_t SPIMEM_RD_ADDR = 0x000000;     // Initialize read address


#endif

The source file to the line of error is:

/*  User functions*/

#include "TimeDelay.h"
#include "user.h"
#include "hardware_profile.h"
#include <plib.h>
#include <p32xxxx.h>
/*  Pointer pointers
 *
 * What sepp2k said is quite correct, but difficult to understand for noobs.
 * Here is possibly a more understandable example:

    int anInt = 5;
    int* ptrToAnInt = &anInt;
    anInt += 2;
    printf("anInt and ptrToAnInt == %d (%d)\n", anInt, *ptrToAnInt);
 * This should result in the output "anInt and ptrToAnInt == 7 (7)".
 * Clear as mud yet? :-)
 */
    void initialize(void)
    {
        // Set up IO ports
        PORTSetPinsDigitalOut(IOPORT_A, BIT_0 | BIT_1 | BIT_2 | BIT_3);
        PORTSetPinsDigitalOut(IOPORT_D, BIT_4 | BIT_5);
        PORTSetPinsDigitalOut(IOPORT_E, BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5);
        PORTSetPinsDigitalIn(IOPORT_D, BIT_6 | BIT_7);

        GREEN_LED_OFF
        RED_LED_ON

        SS_RESET();
        PORTSetBits(IOPORT_E, BIT_0);           // Enable FRAM Write
        PORTClearBits(IOPORT_E, BIT_2 | BIT_3 | BIT_4 | BIT_5); // Turn off both DAC's amplifiers
        RSTDAC();                               // Reset all four DAC(s)

        // Ensure FRAM is calibrated. If high address = 0xFF run calibration
        SS_RESET();
        SS_FRAM();

        // Set up clocks in configuration_bits.c
        // set up SPI
        // set up Timers
        // Reset DAC(s)
        // Set up Ethernet
        // Set up USB
        RED_LED_OFF
        GREEN_LED_ON
    }

//    extern DAC1;

    void SetDAC_High(Voltage_High)
    {
        // VOUT = ((VREFH-VREFL)/65536)*CODE+VREFL
        //      = DAC1_MULT * CODE - 10
        // 1    = (DAC1_MULT * CODE - 10)/VOUT  3*6-10=8  6=8+10/3
        // CODE1 = (int)(Voltage + 10)/DAC1_MULT  (-10+10)/mult =0x0000  (10+10)/mult = 0x10000
        if (Voltage_High>10.000)
            Voltage_High=10;
        if (Voltage_High<-10.000)
            Voltage_High=-10;
        CODE1=int (Voltage_High + 10)/DAC1_MULT;
        if (CODE1 == 65536)
            CODE1--;
        VOUT = (DAC1_MULT * CODE1);
        // CODE2 = (int)(((((Voltage-VOUT)+2.5)*10)/DAC2_MULT)+CalVal)
        Voltage = Voltage_Low;
        CalVal = CALCOR(Voltage);
        CODE2= int(((((Voltage_High-VOUT)*10)+2.5)/DAC2_MULT)+CalVal);
        // SCLK = 50MHz Max
        //

    }
    void SetDAC_Low(Voltage_Low)
    {
        // VOUT = ((VREFH-VREFL)/65536)*CODE+VREFL
        //      = DAC1_MULT * CODE - 10
        // 1    = (DAC1_MULT * CODE - 10)/VOUT  3*6-10=8  6=8+10/3
        // CODE1 = (int)(Voltage + 10)/DAC1_MULT  (-10+10)/mult =0x0000  (10+10)/mult = 0x10000
        if (Voltage_Low>10.000)
            Voltage_Low=10;
        if (Voltage_Low<-10.000)
            Voltage_Low=-10;
        CODE1=int (Voltage_Low + 10)/DAC1_MULT;
        if (CODE1 == 65536)
            CODE1--;
        VOUT = (DAC1_MULT * CODE1);
        // CODE2 = (int)(((((Voltage-VOUT)+2.5)*10)/DAC2_MULT)+CalVal)
        Voltage = Voltage_Low;
        CalVal = CALCOR(Voltage);
        CODE2= int(((((Voltage_Low-VOUT)*10)+2.5)/DAC2_MULT)+CalVal);
        // SCLK = 50MHz Max
        //

    }

    void Set_DAC1(DAC1)
    {
        SPIPORT=4;
        DAC1CODE = (int)((DAC1 + 10) / DAC1_MULT);
        &PortBuffer = DAC1CODE;
        SS_DAC1;
        SPIPORT_Write(SPIPORT, &PortBuffer, 2);
        SS_RESET;

    }

/*    void Set_DAC2(*DAC1Temp)
    {
        // VOUT = Vref((CODE/2^n-1)-1) where Vref = 2.5, n = 16 bit DAC
        //  = 2.5*((CODE/32768)-1)
        //
        PortBuffer = CALCOR(*DAC1Temp);
        SPIPORT = 2;
        SPIPORT_Write(SPIPORT, SS_DAC2, PortBuffer, 2);
    }
*/

/*  interpolationSearch was originally written in Java                        //
int interpolationSearch(int16_t[] CalCor, float Voltage)
{
  // Returns index of toFind in sortedArray, or -1 if not found
  int low = 0;
  int high = sortedArray.length - 1;
  int mid;

  while (sortedArray[low] <= Voltage && sortedArray[high] >= Voltage) {
   mid = low +
         ((toFind - sortedArray[low]) * (high - low)) /
         (sortedArray[high] - sortedArray[low]);  //out of range is possible  here

   if (sortedArray[mid] < toFind)
    low = mid + 1;
   else if (sortedArray[mid] > toFind)
    // Repetition of the comparison code is forced by syntax limitations.
    high = mid - 1;
   else
    return mid;
  }

  if (sortedArray[low] == toFind)
   return low;
  else
   return -1; // Not found
 }
*/

    int16_t CALCOR(float &Voltage)
    {
        // Find which two correction values "Voltage" is between
        //
        // Get Cal correction from FRAM.  See calibration.h for locations
/* 
 *       y = y1 + ((x-x1)*(y2-y1)/(x2-x1)
 *       where x = Voltage
 *       x1 = Lower calibrated value
 *       x2 = Upper calibrated value
 *       y = CalVal
 *       Y1 = calibrated value associated with x1
 *       y2 = calibrated value associated with x2
 */
    }

int16_t must be defined somewhere -- I don't see it defined in any of the code you posted. Check the other included files. I don't know anything ab out XC32, but it may not be standard c or c++ complient since it's intended for embedded programs.

int16_t, uint16_t, int8_t, uint8_t, int32_t, and uint32_t are all defined in a file included in <p32xxxx.h>. The nice thing about Microchip programs is you can CTRL click on the defined word and the program will bring up the file that defined it. It should be standard C with a few added definitions in other files included in <p32xxxx.h> for things like SPI, CAN, I2C, and Ethernet. The Ethernet control has an output for MII, RMII, and SMII communication to a PHY device.

The nice thing about Microchip programs is you can CTRL click on the defined word and the program will bring up the file that defined it.

Visual Studio does that too -- very handy feature :) Other than that, I can't tell you what the problem is because I don't have your compiler.

XC32 is based on the Net Beans C IDE. The part I'm having a problem with should be standard C since it doesn't deal with any of the embedded peripherals.

I solved it. It turned out there was one function that appeared okay. It just lost its "}" at the end.

I spoke too soon. The compiler errors are still there.

Member Avatar for Mouche

Are you sure that int16_t is actually defined? Comment that function out and write your own that returns int and then int16_t. Do you get a compiler error using int16_t?

Do you have any other errors?

These are the definitions

typedef __signed char        __int8_t;
typedef unsigned char       __uint8_t;
typedef short int       __int16_t;
typedef unsigned short int     __uint16_t;
typedef int         __int32_t;
typedef unsigned int           __uint32_t;

In one included file followed by:

#ifndef int8_t
typedef __int8_t    int8_t;
#define int8_t      __int8_t
#endif

#ifndef uint8_t
typedef __uint8_t   uint8_t;
#define uint8_t     __uint8_t
#endif

#ifndef int16_t
typedef __int16_t   int16_t;
#define int16_t     __int16_t
#endif

#ifndef uint16_t
typedef __uint16_t  uint16_t;
#define uint16_t    __uint16_t
#endif

#ifndef int32_t
typedef __int32_t   int32_t;
#define int32_t     __int32_t
#endif

#ifndef uint32_t
typedef __uint32_t  uint32_t;
#define uint32_t    __uint32_t
#endif

#ifndef int64_t
typedef __int64_t   int64_t;
#define int64_t     __int64_t
#endif

#ifndef uint64_t
typedef __uint64_t  uint64_t;
#define uint64_t    __uint64_t
#endif

in another file. Also if a term/variable is undefined it will be underlined in red. #defined terms show up in blue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.