0

I'm pretty rusty in C++, so forgive me for any stupid comments/questions. Right now I'm working in Microsoft Visual C++ 2010 Express. I have two files - a source and a header - and VS is recognizing the header file when I include it, but it cannot find any definitions from within the header file. It shows me 'Error: identifier "RAW_PACKET_SIZE" is undefined'. The code was provided as a sample to work with a device's API, so it should work. I'm assuming the problem is with the VS setup. Here's some intro code form each:

recorder.cpp

#include <vector>
#include "APIW32.h"
#pragma comment(lib,"APIW32.lib")

int devID;
float* buf = new float[RAW_PACKET_SIZE];  // error is here, at 'RAW_PACKET_SIZE'

APIW32.h

#pragma once

#ifdef EXPORTS
#define API __declspec(dllexport)
#else
#define API __declspec(dllimport)
#endif

#define MIN_BW                0.301003456
#define MAX_BW                10100000
#define RAW_PACKET_SIZE       299008

UPDATE:

It appears that the error was only appearing in Intellisense, and not as an actual build error. Moral of the story - Intellisense is not always right!

David K
  • 1,296
  • 18
  • 39
  • 1
    Take a look at the preprocessor out to see what that tells you: http://stackoverflow.com/questions/8978997/how-can-i-see-the-output-of-the-visual-c-preprocessor – NPE Mar 28 '13 at 14:24
  • is RAW_PACKET_SIZE undefined the first error? and try NPEs suggestion – Caribou Mar 28 '13 at 14:25
  • you have syntax error: should be `float * buf = new float[RAW_PACKET_SIZE]`. Is it able to find "MAX_BW" and "MIN_BW"? – taocp Mar 28 '13 at 14:28
  • I tried building it after changing to float* (which I thought to be an unrelated problem). The definition error wasn't in the build output, but the red underline was still there. Closed VS and reopened, and now everything is fine. I'm going to delete this question. – David K Mar 28 '13 at 14:34
  • 2
    You want to say that `'Error: identifier "RAW_PACKET_SIZE" is undefined'` was not a build error, but intellisense error? please, please, please, don't treat Intellisense as a measure of code correctness. – Zdeslav Vojkovic Mar 28 '13 at 14:43
  • @ZdeslavVojkovic, yes, that appears to be the case. Lesson learned! – David K Mar 28 '13 at 14:46
  • Then it is a good day :) I got so fed up with misleading messages that I always keep it turned of in messages window (I also find that Output window provides much more context about errors.) – Zdeslav Vojkovic Mar 28 '13 at 14:55

1 Answers1

2

Try float* buf = new float[RAW_PACKET_SIZE];

Matt
  • 74
  • 3
  • 1
    The compiler should report a syntax error for type mismatch, not reporting undefined `RAW_PACKET_SIZE` if this is the cause. – taocp Mar 28 '13 at 14:32
  • You are correct that that is an error, but that is not what was causing the problem I asked about. – David K Mar 28 '13 at 14:44