Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sizeof(oVel) returns the size of a pointer #3

Open
ghost opened this issue May 9, 2019 · 2 comments
Open

sizeof(oVel) returns the size of a pointer #3

ghost opened this issue May 9, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented May 9, 2019

https://github.com/jwatte/EPIC/blob/master/Extrapolator.cpp#L126

oVel is an argument and passed as pointer to ReadPosition(), so sizeof(oVel) returns the size of a pointer.

Fix

Replace sizeof(oVel) with sizeof(Type) * Count

memset(oVel, 0, sizeof(Type) * Count);
@jwatte
Copy link
Owner

jwatte commented May 9, 2019

#include <stdio.h>

template<int Count, typename Type>
struct bar {
void func(Type x[Count]);
};

template<int Count, typename Type> void bar<Count, Type>::func(Type x[Count]) {
printf("%d\n", (int)sizeof(x));
}

int main() {
int x[10];
bar<10, int> b;
b.func(x);
return 0;
}

foo.cpp:9:29: warning: ‘sizeof’ on array function parameter ‘x’ will return size of ‘int*’

Never a dull moment in C++ world.

Thanks for the report!

@ghost
Copy link
Author

ghost commented May 10, 2019

Yes, GCC and Clang do an amazing job. I just noticed it, because I compiled a program with Clang. VS2017 didn't complain about that (didn't try with VS2019 yet).

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant