.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
sizeof of argument array might be suprising...
Old
  (#1)
ghost of evilspy
Moderator
 
ghost of evilspy's Avatar
 
Status: Offline
Posts: 140
Join Date: Mar 2005
Location: Finland
Default sizeof of argument array might be suprising... - 17-07-2007

Just something I wasn't aware of...

Code:
#include <stdio.h>

int test_array1[] = { 1,2,3,4,5,6, };

int func_test_array3(int test_array3[6])
{
	return(sizeof(test_array3));
}

int func_test_array5(int len)
{
	int test_array5[len];
	
	return(sizeof(test_array5));
}

int main(void)
{
	int test_array2[6];
	int test_array4[] = {1,2,3,4,5,6,};
	
	printf("sizeof(test_array1): %d\n", sizeof(test_array1));
	printf("sizeof(test_array2): %d\n", sizeof(test_array2));
	printf("sizeof(test_array3): %d\n", func_test_array3(test_array2));
	printf("sizeof(test_array4): %d\n", sizeof(test_array4));
	printf("sizeof(test_array5): %d\n", func_test_array5(6));
	
	return(0);
}
Code above outputs:
sizeof(test_array1): 24
sizeof(test_array2): 24
sizeof(test_array3): 4
sizeof(test_array4): 24
sizeof(test_array5): 24
  
Reply With Quote
Re: sizeof of argument array might be suprising...
Old
  (#2)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: sizeof of argument array might be suprising... - 18-07-2007

the arrays in parameters are the same as pointers, so that's why you got result like that.

i.e.,

int func_test_array3(int test_array3[6])

is 100% the same as:

int func_test_array3(int *test_array3)
  
Reply With Quote
Re: sizeof of argument array might be suprising...
Old
  (#3)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: sizeof of argument array might be suprising... - 18-07-2007

yep. ... I should reload before posting


  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com