473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Visual C++ Error 2143

I'm getting a stranger error that I can't seem to figure out. I'm
using Visual C++ 6.0 and trying to compile the following code: (I've
pointed out the line that throws the "error C2143: syntax error :
missing ';' before '['")

#include <algorithm>
#include "frame.h"
#include "myio.h"

int Frame::read() {
int Lf; //Length of segment
int hv;

Lf=read2bytes();
P=readbyte();
y=read2bytes(); x=read2bytes();
nc=readbyte();

hmax=vmax=-1;
for (int i=0;i<nc;i++) {
c[i].id=readbyte();
idloc[c[i].id]=i;
hv=readbyte();
c[i].h=hv>>4; c[i].v=hv & 0xF;
if (c[i].h>hmax) hmax=c[i].h; if (c[i].v>vmax) vmax=c[i].v;
c[i].Tq=readbyte();
}

if (nError) return 0;
return 1;
}

void Frame::extenddata(int row) {
for (;ndatarow<row;ndatarow++) {
data[ndatarow]=new (int *) [nc]; //<--- This is the line with
the error!
for (int i=0;i<nc;i++)
data[ndatarow][i]=new int[x+40];
}
}

void Frame::cleardata() {
for (int i=0;i<ndatarow;i++) {
for (int j=0;j<nc;j++)
delete [] data[i][j];
delete [] data[i];
}
ndatarow=0;
}

Frame::~Frame() {
cleardata();
}

void Frame::write() {
write2bytes(0xFFC0); //SOF0 - Start of Frame 0: Baseline DCT
write2bytes(8+3*nc); //Length of marker segment
writebyte(P);
write2bytes(y); write2bytes(x);
writebyte(nc);
for (int i=0;i<nc;i++) {
writebyte(c[i].id);
writebyte((c[i].h<<4)|(c[i].v));
writebyte(c[i].Tq);
}
}

Anyone gots any ideas? I've totally stumped!
Thanks for your help,
--Ryan
Jul 22 '05 #1
4 3394
"Ryan" <sc******@student.umass.edu> wrote...
I'm getting a stranger error that I can't seem to figure out. I'm
using Visual C++ 6.0 and trying to compile the following code: (I've
pointed out the line that throws the "error C2143: syntax error :
missing ';' before '['")
[...]
data[ndatarow]=new (int *) [nc]; //<--- This is the line with
Drop the parentheses.
the error!
[...]


Victor
Jul 22 '05 #2
Victor,
I'm getting a stranger error that I can't seem to figure out. I'm
using Visual C++ 6.0 and trying to compile the following code: (I've
pointed out the line that throws the "error C2143: syntax error :
missing ';' before '['")
[...]
data[ndatarow]=new (int *) [nc]; //<--- This is the line with the error

Drop the parentheses.

That didn't seem to work for me. I continued looking at this last
night and it seems that since nc is an int, that this line is trying
to cast the value of int nc to int *. Truth be told I'm not sure what
int * is, but I think it's a pointer. Is this true? If so, I don't
believe you can do this in C++, but rather more of a C operation. Am
I way off track here? If not, I'm still not sure how to fix it. Any
other suggestions?
Thanks all,
--Ryan
Jul 22 '05 #3
Ryan wrote:
That didn't seem to work for me. I continued looking at this last
night and it seems that since nc is an int, that this line is trying
to cast the value of int nc to int *. Truth be told I'm not sure what
int * is, but I think it's a pointer. Is this true? If so, I don't
believe you can do this in C++, but rather more of a C operation. Am
I way off track here? If not, I'm still not sure how to fix it. Any
other suggestions?


typedef int * pInt;
new pInt[nc];

VC++ has a bug with the "maximum munch" rules (or a similarly named rule).
The tokens following 'new' must be parsed for as long as the result could be
a type. But VC++ may have treated the () as argument delimiters.

VC++ is also supposed to do this properly:

SimCity & aCity (getSimCity());

But it won't.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #4
Ryan wrote:
I'm getting a stranger error that I can't seem to figure out. I'm
using Visual C++ 6.0 and trying to compile the following code: (I've
pointed out the line that throws the "error C2143: syntax error :
missing ';' before '['")
[...]
data[ndatarow]=new (int *) [nc]; //<--- This is the line with the error
I wrote
Drop the parentheses.



Ryan wrote then
That didn't seem to work for me.
WTF do you mean by "didn't seem to work"? Did it work or didn't it?
I continued looking at this last
night and it seems that since nc is an int, that this line is trying
to cast the value of int nc to int *.
No. It is a syntactically incorrect way of invoking "placement new".
Truth be told I'm not sure what
int * is, but I think it's a pointer. Is this true?
Yes, 'int*' is a pointer.
If so, I don't
believe you can do this in C++, but rather more of a C operation.
Huh?
Am
I way off track here? If not, I'm still not sure how to fix it. Any
other suggestions?


Since you didn't provide the definition of 'Frame' in your original
post, I assumed it has a data pointer called 'data', which is an array
of pointers to int or a pointer to a pointer to int. Is it?

Now, have you actually _tried_ removing the parentheses? With them the
statement looks a bit like a "placement new" but in fact is missing some
vital parts, besides, the expression in the parentheses must evaluate to
a real pointer. You, OTOH, have a type-id in the parentheses. That's not
acceptable.

Write your expression as

data[ndatarow] = new int*[nc];

and then read the chapter on dynamic memory allocation in your favourite
C++ book.

Victor
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
0
by: gerd | last post by:
Hello, I want to port an MFC Application from Visual Studio 6 MFC application to Visual C++ 2005 express edition beta. While building i get following error: ------ Build started: Project:...
0
by: gerd | last post by:
Hello, I want to port an MFC Application from Visual Studio 6 MFC application to Visual C++ 2005 express edition beta. While building i get following error: ------ Build started: Project:...
19
by: Alf P. Steinbach | last post by:
// As usual the error message directs one to the report the bug. // // And as usual there is absolutely no way to do so without paying for // the privilege... // // Or using three or four hours...
5
by: Microsoft | last post by:
Hi, I have Visual Basic .net 2003 (Standard Edition) & SQL Server 2000 Developer Edition. When trying to create a connection in the server explorer from the .net IDE I get a number of problems;...
1
by: KevinGPO | last post by:
My application was developed under Visual C++ 6.0, ATL, MFC & PlatformSDK Feb2003 (the last VC6 compatible version). I am wondering if PlatformSDK Feb2003 is compatible with Visual Studio.NET...
11
by: MLH | last post by:
Private Sub ButtonP_Click() On Error GoTo Err_ButtonP_Click Dim ThisForm As String ThisForm = Me.Name Exit_ButtonP_Click: Exit Sub Err_ButtonP_Click: Dim r As String, k As String, Message3...
0
jwwicks
by: jwwicks | last post by:
Introduction This tutorial describes how to use Visual Studio to create a new C++ program, compile/run a program, resume work on an existing program and debug a program. It is aimed at the...
3
by: Johnson | last post by:
I'm not sure if this is an IIS 5.1 issue or ASP.NET issue, or Visual Studio 2008 issue -- thus posting to 3 groups. Please don't be offended. The problem I'm encountering is that Visual Studio...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.