Under "normal conditions" sizeof of an array covers the whole array. is this different for function paramters?
Am 06.02.2011 14:50, schrieb pschweitzer@svn.reactos.org:
Author: pschweitzer Date: Sun Feb 6 13:50:57 2011 New Revision: 50612
URL: http://svn.reactos.org/svn/reactos?rev=50612&view=rev Log: [NTOSKRNL/PPC] Fix the fix, spotted by "ThFabba" on IRC
Modified: trunk/reactos/ntoskrnl/ke/powerpc/cpu.c
Modified: trunk/reactos/ntoskrnl/ke/powerpc/cpu.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/powerpc/cpu.c?r... ============================================================================== --- trunk/reactos/ntoskrnl/ke/powerpc/cpu.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ke/powerpc/cpu.c [iso-8859-1] Sun Feb 6 13:50:57 2011 @@ -44,7 +44,7 @@ CPUID(IN ULONG CpuInfo[4], IN ULONG InfoType) {
- RtlZeroMemory(CpuInfo, sizeof(CpuInfo) * sizeof(ULONG));
RtlZeroMemory(CpuInfo, 4 * sizeof(ULONG)); }
VOID
Hey,
Yes, array arguments are just simple pointers in C, so sizeof will return the size of a pointer to the base type. Exercise for the reader: Predict what happens when you try passing an int[4] into an int[8] argument.
WBR,
Roel Messiant
2011/2/6 Timo Kreuzer timo.kreuzer@web.de:
Under "normal conditions" sizeof of an array covers the whole array. is this different for function paramters?
Am 06.02.2011 14:50, schrieb pschweitzer@svn.reactos.org:
Author: pschweitzer Date: Sun Feb 6 13:50:57 2011 New Revision: 50612
URL: http://svn.reactos.org/svn/reactos?rev=50612&view=rev Log: [NTOSKRNL/PPC] Fix the fix, spotted by "ThFabba" on IRC
Modified: trunk/reactos/ntoskrnl/ke/powerpc/cpu.c
Modified: trunk/reactos/ntoskrnl/ke/powerpc/cpu.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/powerpc/cpu.c?r...
============================================================================== --- trunk/reactos/ntoskrnl/ke/powerpc/cpu.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ke/powerpc/cpu.c [iso-8859-1] Sun Feb 6 13:50:57 2011 @@ -44,7 +44,7 @@ CPUID(IN ULONG CpuInfo[4], IN ULONG InfoType) {
- RtlZeroMemory(CpuInfo, sizeof(CpuInfo) * sizeof(ULONG));
- RtlZeroMemory(CpuInfo, 4 * sizeof(ULONG));
}
VOID
Ros-dev mailing list Ros-dev@reactos.org http://www.reactos.org/mailman/listinfo/ros-dev
Hi, this is a bit tricky, but it is the way it works. In case you still have doubts, enjoy that C program. You will never reach the memset:
#include <assert.h> #include <string.h>
void test_sizeof(unsigned long test[4], char c) { assert(sizeof(test) == (4 * sizeof(unsigned long))); memset(test, c, sizeof(test)); } void main() { unsigned long tab[4]; test_sizeof(tab, '?'); }
Regards, P. Schweitzer
Hey,
Yes, array arguments are just simple pointers in C, so sizeof will return the size of a pointer to the base type. Exercise for the reader: Predict what happens when you try passing an int[4] into an int[8] argument.
WBR,
Roel Messiant