Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Sizeof array increases by one byte after passing it to a function

  • 25-06-2008 9:32pm
    #1
    Closed Accounts Posts: 12,382 ✭✭✭✭


    Hello

    I was wondering if any of you have an explanation for this.
    int main()
    {
    	unsigned char a[] = {0x00, 0x80, 0x81};
    	unsigned char b[] = {0x00, 0x18, 0x00};
    
    	printf("sizeof a: %d\n", sizeof a);
    
    	multiply(a, b, f);
    }
    

    This outputs the text "sizeof a: 3".

    The multiply function is then called:
    void multiply(unsigned char *a, unsigned char *b) {
    
    	printf("sizeof a: %d\n", sizeof a);
    }
    

    This outputs the text "sizeof a: 4".

    ???

    Can any of you think of an explanation for this?

    Thanks in advance.


Comments

  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    Thinking about this some more, I can see it's the size of the pointer to the array I'm seeing in the multiply function.

    Does anyone know how I can get it to output the size of the array?


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    The first sizeof is getting the size of an array, which is 3, the sizeof in multiply is getting the sizeof a pointer to an unsigned char.

    EDIT, Oh you realised... There isn't really a way to tell the length in C or C++, You'd have to pass size values to the multiply function.


Advertisement