Results 1 to 10 of 10
Hi all,
I just have basic doubt on sizeof. any function name size is giving as 1 byte.
int main()
{
printf("%d", sizeof(main); // or
printf("%d", sizeof(printf));
return 0;
}
...
- 04-21-2009 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 49
sizeof function
Hi all,
I just have basic doubt on sizeof. any function name size is giving as 1 byte.
int main()
{
printf("%d", sizeof(main); // or
printf("%d", sizeof(printf));
return 0;
}
or some user defined function also the same.
Please any one tell, why it is giving as 1 byte, if it pointer i can understand that it is 4 bytes.
- 04-21-2009 #2
#include<iostream>
using namespace std;
int main()
{
cout << sizeof(main());
return 0;
}
It returns 4.
- 04-21-2009 #3
It should be returning either 4 or 8 bytes depending on the system 32 or 64 bit....Gerard4143
Make mine Arch Linux
- 04-21-2009 #4
he wrote sizeof(main) instead sizeof(main())
- 04-21-2009 #5
- 04-21-2009 #6Just Joined!
- Join Date
- Apr 2009
- Location
- South East England
- Posts
- 40
Remember that although a function pointer can be assigned to from the function name, the function name itself is not a pointer. K&R states that sizeof cannot be applied to an operator of function type, and that if you do you will get an implementation-dependant unsigned integer ... in your case 1 it would seem.
I think the trick is to do sizeof(&main).
- 04-22-2009 #7
- 04-24-2009 #8Just Joined!
- Join Date
- Aug 2008
- Posts
- 49
find executable file path
Hi All,
I have to find the executable file path by using the PID (process ID).
User will input some PID and required output is corresponding executable file path.
For this i have to write a C program using system call. Anyone help me.
- 04-24-2009 #9Just Joined!
- Join Date
- Apr 2009
- Location
- South East England
- Posts
- 40
- 04-24-2009 #10


Reply With Quote
