1

I am currently learning how to write my own library for my mbed electronics project. So far I have two files cfExtensions.cpp and cfExtensions.h files. I referenced my variables in the cfExtensions.h constructor and changed their values within my cfExtensions.cpp file; however my mbed c++ compiler throws: identifier "phMin" is unidentified. My code is:

FILE: cfExtensions.h /* File: cfExtensions.h

Header file for cfExtensions Library.
*/

#ifndef __cfExtns_H
#define __cfExtns_H

#include "mbed.h"

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//==================================
// Definitions
//==================================
#define CF_FILE_LOCATION  "local/settings.cf"     // File location local/settings.cf

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//==================================
// cfExtension Class
//==================================
class cfExtensions
{
public:
//---------------------------
// Function Prototypes
//---------------------------
        cfExtensions();                         // Constructor, Initialisation tasks

        void loadConfigFile();                  // Loads config file defined in CF_FILE_LOCATION
        void checkConfigForFirstStart();        // Check if MBED startup is the very first startup
        void getPhMaxValueFromConfigFile();     // Get PH Max value from config file
        void getPhMinValueFromConfigFile();     // Get PH Min value from config file
        void getKeyAndValue();


//---------------------------
// Variables
//---------------------------
        volatile bool pingTicked;

        bool linkedWithBaseStation;

        char *sbNameKey;
        char sbNameValue[BUFSIZ];

        char *sbFirstStartKey;
        char sbFirstStartValue[BUFSIZ];

        char *sbUseBaseStationKey;
        char sbUseBaseStationValue[BUFSIZ];

        char *sbPhMaxKey;
        char sbPhMaxValue[BUFSIZ];

        char *sbPhMinKey;
        char sbPhMinValue[BUFSIZ];

        float phMax;
        float phMin;


//---------------------------
// Devices
//--------------------------- 

};

#endif

FILE: cfExtensions.cpp

//================================
// Get PH Min Value from CF
//================================
void getPhMinValueFromConfigFile() {    
    /*
     * Get a configuration value.
     * Then attach the sbNameValue to SensorData json
     */
    if (cfg.getValue(sbPhMinKey, &sbPhMinValue[0], sizeof(sbPhMinValue))) {
        phMin = atof(sbPhMinValue);
    }
} // End of getPhMinValueFromConfigFile
BenMorel
  • 34,448
  • 50
  • 182
  • 322
dottedquad
  • 1,371
  • 6
  • 24
  • 55
  • 2
    `__cfExtns_H` is a bad name to choose. It's reserved because it contains adjacent underscores. For other rules, see here: http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier – chris Oct 18 '12 at 04:34
  • @chris I changed __cfExtns_H to CF_Extns_H – dottedquad Oct 18 '12 at 20:46

2 Answers2

1

I think it should be void cfExtensions::getPhMinValueFromConfigFile() { } in your cfExtensions.cpp file.

Aniket Inge
  • 25,375
  • 5
  • 50
  • 78
  • 1
    Yes, otherwise without it, `getPhMinValueFromConfigFile` is yet another function to C++ compiler. – g13n Oct 18 '12 at 04:37
  • @Prototype That worked as it should. The compiler no longer throws that error; however, I am still getting a warning: "variable "sbNameKey" was declared but never referenced" in file "/cfExtensions.cpp", Line: 25, Col: 10 I believe I referenced(I think that is the proper term) the variables in my cfExtensions.h file and change the values in the cpp. How do I properly call the variables so I can use the values and set their values? – dottedquad Oct 18 '12 at 20:54
  • @dottedquad to get rid of that warning: `sbNameKey = sbNameKey;` . I really don't understand what you meant by "call" the variables :-s – Aniket Inge Oct 18 '12 at 20:56
  • @PrototypeStark I'm sorry, I do not know the proper terminology. By 'call' I mean how do I handle the variable so that warning no longer exists, but you already explained to `sbNameKey = sbNameKey` Is that really necessary since it is only a warning? I am interested in learning the 'proper'(if there is a such thing) way of writing code. If I write `sbNameKey = sbNameKey;` is it really necessary to place the variables in the .h? Can I just reference and declare all my variables in the .cpp file or is that not good coding practice? – dottedquad Oct 19 '12 at 03:23
  • @dottedquad its just a warning that you have an unused variable. And for terminology: its called "variable unused warning". That's used by most compilers of this day to tell you: "You defined something and you never used it". its like your mom telling you "you bought a piano and never touched a key on it :| (my mom said)". lol – Aniket Inge Oct 19 '12 at 07:40
1

In the cpp file change the function implementation to

void cfExtensions::getPhMinValueFromConfigFile() {
  // etc ....
}

The key here is to have cfExtensions:: in front of the function.

cha
  • 10,301
  • 1
  • 18
  • 26