Question

I have a line of source code:

time_t l1_QuoteTime;

I am getting the following error for it:

[BCC32 Error] QuoteDefs.h(18): E2303 Type name expected
  Full parser context
    Unit1.cpp(7): #include api\dasapi.h
    dasapi.h(13): #include api\QuoteDefs.h
    QuoteDefs.h(9): class st_L1Quotes

I have included <time.h>. What am I missing here?


Code:

class st_L1Quotes
{
public:
    char secsym[10];
    char PrimExch;
    int mstatus;
    double l1_BidPrice;
    int l1_BidSize;
    double l1_AskPrice;
    int l1_AskSize;
    time_t l1_QuoteTime;
    double l1_lastPrice;
    double l1_todayhigh;
    double l1_todaylow;
    double l1_todayclose;
    int l1_volume;
    double l1_yclose;
    double l1_todayopen;
    double l1_LastBidPrice;
    // this is used for show up/down arrow for NASDAQ NMS stocks;
};
Was it helpful?

Solution

Where is <time.h> (should that be <ctime>) included w.r.t the "api/dasapi.h" header?

Indeed, the QuoteDefs.h header should probably #include either <time.h> or <ctime> itself since it cannot be used unless that include is present. I can see how the time_t on the 11th line in the code snippet as formatted by me could be on the 9th line in your formatting of the code, but there isn't room for header protection guards or the necessary #include.

General tip:

  • Headers should be self-contained and idempotent.

Self-contained means that you should be able to write:

#include "header.h"

at the top of a file and the code should compile cleanly.

Idempotent means that it should not matter if the header is included twice. Usually, that wouldn't be done directly; rather the source would include the header directly and some other header would also include the header indirectly (or two other headers would include it indirectly). Think what a nuisance it would be if you could only include <stdio.h> or <iostream> once!

You can test idempotency by writing:

#include "header.h"
#include "header.h"

at the top of a file and the code should compile cleanly.

I even have a script called chkhdr to automate the test:

#!/bin/ksh
#
# @(#)$Id: chkhdr.sh,v 1.3 2011/07/25 07:09:49 jleffler Exp $
#
# Check whether a header can be compiled standalone

tmp=chkhdr-$$
trap 'rm -f $tmp.?; exit 1' 0 1 2 3 13 15

cat >$tmp.c <<EOF
#include HEADER /* Check self-containment */
#include HEADER /* Check idempotency */
int main(void){return 0;}
EOF

options=
for file in "$@"
do
    case "$file" in
    (-*)    options="$options $file";;
    (*)     echo "$file:"
            ${CC:-gcc} $options -DHEADER="\"$file\"" -c $tmp.c
            ;;
    esac
done

rm -f $tmp.?
trap 0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top