Hi all again, It feels like we are getting off topic a bit ....
The code snippet I supplied may seem strange but it is taken out of context.
It shows where I got an error and some surrounding code and definitions as requested.
I don't have any C-code that I've 'translated', that was just a reason I mentioned wy I choosed
Delphi compatible so many years ago. ( I Think it was some DirectX headers I downloaded that would't compile without it and my own code didn't seem to care so I went along with it.)
What's best or most practical is not the issue here,though any thougths is appreciated for future use
This code Do compile and work under 2.4.1 but Not in 2.6.4 !
My original question was wy I'm not allowed to do this pointer arithmetics anymore,
I't might be strange but I find it useful when you know what you're doing ( You know what
Type/Record/ etc. resides ( or should reside
) at that memory location. There might be a
better way of doing this but I find this way easy enough. I'ts the best way I've come up with
interpreting C-calls with olny a pointer as input, there you can typecast in the function declaration
and later access Arrays/Records as you please( It seems, Pascal is much moore strict but this is how I have dealt with it).
I will Supply some broken out code ,fpc configfile used and a dump of compiler messages using
the same cfg file only alternating the Mode.
Type
stsc_entry = Record
first_chunk : Dword;
samples_per_chunk : Dword;
sample_description_index : Dword;
end;
Var
{$A4}
stsc : Record
entry_count : Dword;
buffer : ^stsc_entry;
buffer_Size : Dword;
end;
SomeMemory : Array[0..1023] of byte;
Function Get_Sample_From_File(dest : pointer; MaxSize,Sample_Index : Dword) : integer;
Var
Size,Offset,indx,BytesRead,Res : Dword;
i,idx,chunk : integer;
begin
// Get Sample using stco and stsz information
// Get chunk from stsc
i := 0; idx := 0;
chunk := (stsc.Buffer+i)^.first_chunk;
while idx < Sample_index do
begin
indx := idx;
inc(idx,((stsc.Buffer + i)^.samples_per_chunk));
if idx >= Sample_index then break;
inc(chunk);
if i < stsc.entry_count then
begin // are there more entries ? if so
if (stsc.Buffer+i+1)^.first_chunk = chunk then inc(i);
end;
end;
end;
Begin
// initialize
stsc.entry_count := 1;
stsc.Buffer := @SomeMemory[20];
stsc.Buffer_Size := 1023;
Get_Sample_From_File(@SomeMemory[0],1023,5);
end.
// -----------------------------------------------------------------------------------------------------------
// New Compiler
e:\FPC\2.6.4\bin\i386-win32>fpc -iD -iW
2014/03/06 2.6.4
e:\FPC\2.6.4\bin\i386-win32>fpc e:\fpc\chrille\test\compilertest.pas
Target OS: Win32 for i386
Compiling e:\fpc\chrille\test\compilertest.pas
compilertest.pas(26,10) Warning: Function result does not seem to be set
compilertest.pas(28,5) Note: Local variable "Size" not used
compilertest.pas(28,10) Note: Local variable "Offset" not used
compilertest.pas(28,17) Note: Local variable "indx" is assigned but never used
compilertest.pas(28,22) Note: Local variable "BytesRead" not used
compilertest.pas(28,32) Note: Local variable "Res" not used
Linking E:\FPC\EXE\compilertest.exe
61 lines compiled, 0.9 sec , 35392 bytes code, 1836 bytes data
1 warning(s) issued
5 note(s) issued
e:\FPC\2.6.4\bin\i386-win32>fpc e:\fpc\chrille\test\compilertest.pas
Target OS: Win32 for i386
Compiling e:\fpc\chrille\test\compilertest.pas
compilertest.pas(36,24) Error: Operation "+" not supported for types ".^stsc_ent
ry" and "LongInt"
compilertest.pas(41,27) Error: Operation "+" not supported for types ".^stsc_ent
ry" and "LongInt"
compilertest.pas(41,5) Error: Incompatible types: got "untyped" expected "LongIn
t"
compilertest.pas(47,23) Error: Operation "+" not supported for types ".^stsc_ent
ry" and "LongInt"
compilertest.pas(62) Fatal: There were 4 errors compiling module, stopping
Fatal: Compilation aborted
Error: e:\FPC\2.6.4\bin\i386-win32\ppc386.exe returned an error exitcode (normal
if you did not specify a source file to be compiled)
// -----------------------------------------------------------------------------------------------------------
// Old Compiler
e:\FPC\2.4.1\bin\i386-win32>fpc -iD -iW
2010/01/21 2.4.1-r1:14761
e:\FPC\2.4.1\bin\i386-win32>fpc e:\fpc\chrille\test\compilertest.pas
Target OS: Win32 for i386
Compiling e:\fpc\chrille\test\compilertest.pas
compilertest.pas(26,10) Warning: Function result does not seem to be set
compilertest.pas(28,5) Note: Local variable "Size" not used
compilertest.pas(28,10) Note: Local variable "Offset" not used
compilertest.pas(28,17) Note: Local variable "indx" is assigned but never used
compilertest.pas(28,22) Note: Local variable "BytesRead" not used
compilertest.pas(28,32) Note: Local variable "Res" not used
Linking E:\FPC\EXE\compilertest.exe
61 lines compiled, 0.10 sec , 35872 bytes code, 1744 bytes data
1 warning(s) issued
5 note(s) issued
e:\FPC\2.4.1\bin\i386-win32>fpc e:\fpc\chrille\test\compilertest.pas
Target OS: Win32 for i386
Compiling e:\fpc\chrille\test\compilertest.pas
compilertest.pas(26,10) Warning: Function result does not seem to be set
compilertest.pas(28,5) Note: Local variable "Size" not used
compilertest.pas(28,10) Note: Local variable "Offset" not used
compilertest.pas(28,17) Note: Local variable "indx" is assigned but never used
compilertest.pas(28,22) Note: Local variable "BytesRead" not used
compilertest.pas(28,32) Note: Local variable "Res" not used
Linking E:\FPC\EXE\compilertest.exe
61 lines compiled, 0.10 sec , 35872 bytes code, 1744 bytes data
1 warning(s) issued
5 note(s) issued
// -------------------------------------------------------------------------------------------------------------
// Config file used in all compilations (fpc.cfg) with -M switch altered
-TWin32
# -Mobjfpc
-Mdelphi
-vw
-vi
-vn
-Sg
-Si
-Sc
-Ct
-Ci
-Co
# -Cg
-CX
-Ooregvar
-O1
-O2
-CpPENTIUM4
-OpPENTIUM4
-Rintel
-FEE:\FPC\EXE
-FUE:\FPC\PPU
-gl
-p-
-b-
Hope for suggestions/explanations
User137 : It did pass the first test when I tried typecasting to ptruint but still complains
abaout illegal qualifier ....