fatlardo
February 17th, 2008, 11:56 AM
I have a problem with declaring a variable in a constructor. The problem I get is that, although the code compiles and runs (with no exceptions raised or anything like that), when I pause the code with my debugger, the variable tagsize is non-existent. In fact, none of the local variables declared within the constructor are there!
I tried moving tagsize and renaming it (it was originally called 'size') to no avail. (I chose tagsize as the one to investigate as it was the one causing the code to malfunction and, until writing this post, I hadn't thought about my other local variables).
My code for the constructor is as follows:
ID3v2::ID3v2(char* file) {
//Open File
//Check file exists
if (!FileExists(file)) {
//File does not exist - exit
return;
}
FILE* f;
f = fopen (file, "rb");
unsigned char* readin;
int tagsize = 0;
while (feof(f) == 0) {
//Find "ID3" ($49 44 33)
//While (feof(f) == 0) used because loop is controlled by
//continue and break statements. The feof control ensures
//the loop exits if the end of file is reached
while (feof(f) == 0) {
readin = new unsigned char[10];
fread (readin, 1, 10, f);
int pos49 = 0;//inArray(0x49, readin);
//Not present
if (pos49 < 0) {
//Continue searching
continue;
}
//Present, but rest of "ID3" is beyond end of array
if (pos49 > 7) {
//Seek to start of potential "ID3" and continue searching
//(Will pick up on 0x49 next iteration)
fseek(f, pos49 - 10, SEEK_CUR);
continue;
}
//Found "ID3"
if (readin[pos49 + 1] == 0x44 && readin[pos49 + 2] == 0x33) {
//Seek to start and break loop
fseek(f, pos49 - 10, SEEK_CUR);
break;
}
}
//Check for end of file
if (feof(f) != 0) {
break;
}
//Position is now at the start of the tag
try {
processTagHeader(f, tagsize);
while (tagsize > 0) {
try {
processFrame(f, tagsize);
} catch (eInvalidFrameHeader e) {
//Error processing frame header, skip rest of tag
cout << e.what() << endl;
break;
}
}
} catch (eInvalidTagHeader e) {
//Error processing tag header - skip entire tag
//(achieved by position of this catch)
cout << e.what() << endl;
}
}
}
Anyone see any reason why this shouldn't work?
I tried moving tagsize and renaming it (it was originally called 'size') to no avail. (I chose tagsize as the one to investigate as it was the one causing the code to malfunction and, until writing this post, I hadn't thought about my other local variables).
My code for the constructor is as follows:
ID3v2::ID3v2(char* file) {
//Open File
//Check file exists
if (!FileExists(file)) {
//File does not exist - exit
return;
}
FILE* f;
f = fopen (file, "rb");
unsigned char* readin;
int tagsize = 0;
while (feof(f) == 0) {
//Find "ID3" ($49 44 33)
//While (feof(f) == 0) used because loop is controlled by
//continue and break statements. The feof control ensures
//the loop exits if the end of file is reached
while (feof(f) == 0) {
readin = new unsigned char[10];
fread (readin, 1, 10, f);
int pos49 = 0;//inArray(0x49, readin);
//Not present
if (pos49 < 0) {
//Continue searching
continue;
}
//Present, but rest of "ID3" is beyond end of array
if (pos49 > 7) {
//Seek to start of potential "ID3" and continue searching
//(Will pick up on 0x49 next iteration)
fseek(f, pos49 - 10, SEEK_CUR);
continue;
}
//Found "ID3"
if (readin[pos49 + 1] == 0x44 && readin[pos49 + 2] == 0x33) {
//Seek to start and break loop
fseek(f, pos49 - 10, SEEK_CUR);
break;
}
}
//Check for end of file
if (feof(f) != 0) {
break;
}
//Position is now at the start of the tag
try {
processTagHeader(f, tagsize);
while (tagsize > 0) {
try {
processFrame(f, tagsize);
} catch (eInvalidFrameHeader e) {
//Error processing frame header, skip rest of tag
cout << e.what() << endl;
break;
}
}
} catch (eInvalidTagHeader e) {
//Error processing tag header - skip entire tag
//(achieved by position of this catch)
cout << e.what() << endl;
}
}
}
Anyone see any reason why this shouldn't work?