I have a code snippet below, I’m not quite sure what the last line does. More specifically what’s a Bytef[]?
FILE* read_file_handle = fopen(read_filename, "rb");
fseek(read_file_handle, 0, SEEK_END);
size_t no_bytes_to_read = ftell(read_file_handle);
Bytef* read_buffer = new Bytef[no_bytes_to_read];
What is the Bytef[] do? And, if anyone knows, when porting that to PHP, how would I do that?
I thought it might be an array, but such a variable has never been defined and with the new keyword it just wouldn’t make sense.
Can anyone help?
Hosh
EDIT:
Okay so thanks to the user Default it seems to be something defined within zlib.
It’s defined as typedef Byte FAR Bytef; in this file on line 124
Anyone know what the type of Bytef is according to that?
Byte has been defined as a char (typedef unsigned char Byte;) and FAR has been defined: #define FAR
Any help?
new Bytef[no_bytes_to_read]simply allocates an array ofBytefobjects with a length ofno_bytes_to_read.If you are porting to PHP, as you say, you may want to review PHP arrays. I’m no PHP expert, but it appears that because arrays are implemented as ordered maps, you cannot preallocate – so there is no direct translation of that line.
Additionally, as Default pointed out in the link in his comment, a
Bytef(which appears to be a part of the zlib library) is just another name for aByte, which is itself just a typedef for anunsigned char.To address your edited question –
#define FARsimply creates that symbol. It does nothing in this case – the preprocessor simply strips it. So ultimatelyBytefis just another name for an unsigned, 8-bit byte.