Sponsored Content
Full Discussion: sizeof
Top Forums Programming sizeof Post 86196 by ramneek on Wednesday 12th of October 2005 02:38:07 AM
Old 10-12-2005
but i am getting the result as zero

my program is like this


struct foo
{
char c[];

};


void main()
{
struct foo s;
cout<<sizeof(s);
}



when i compile this and run on solaris 5.8 it gives the output as 0
i dont know why

there is no error in my compilation
 

6 More Discussions You Might Find Interesting

1. Programming

sizeof an array of structure without using 'sizeof' operator

Hi All, is it possible to find out the size of an array of structures ( without using 'sizeof' operator). The condition is we have the array of structure instant but we are not aware of the elements inside the structure. Can someone help me out? Thanks in advance. (18 Replies)
Discussion started by: rvan
18 Replies

2. Programming

How to get the sizeof char pointer

The below code throws the error, since the size of x = 19 is not passed to the cstrCopy function. using namespace std; static void cstrCopy(char *x, const char*y); int main () { char x; const string y = "UNIX FORUM"; cstrCopy(x,y.c_str()); return 0; } void cstrCopy(char *x,... (3 Replies)
Discussion started by: SamRoj
3 Replies

3. Programming

Doubts regarding sizeof() operator

Hi, There are some bewildering sizeof() questions I have in my mind. Could anyone shed some light on this? int main() { printf("%d\n", sizeof(main)); // Ans: 1 } That is, the sizeof() a function identifier though it is treated internally as a pointer gives 1 byte always, why? ... (5 Replies)
Discussion started by: royalibrahim
5 Replies

4. Programming

sizeof(object) in C++

Hi, I have defined the class and call the sizeof(object to class) to get the size. # include <iostream> # include <iomanip> using namespace std; class sample { private: int i; float j; char k; public: sample() { } (2 Replies)
Discussion started by: ramkrix
2 Replies

5. Shell Programming and Scripting

Sizeof a file from directory path in perl

Hai how to find size of a file?? ex : /home/kiran/pdk/sample/calibre this is a path In that I have to find size of a files in side a calibre(it is the folder) like .results or .summary (1 Reply)
Discussion started by: kiran425
1 Replies

6. Programming

Compiler/Runtime uses of sizeof

Ignoring other considerations for a moment and in general ... Would there be a difference in result (dot oh or execution) of: A. strncpy( a, b, sizeof(a) ); vs. B. c = sizeof(a); strncpy( a, b, c ); My general understanding is (at least I think my understanding is) that... (10 Replies)
Discussion started by: GSalisbury
10 Replies
libtalloc_debugging(3)						      talloc						    libtalloc_debugging(3)

NAME
libtalloc_debugging - Chapter 6: Debugging Although talloc makes memory management significantly easier than the C standard library, developers are still only humans and can make mistakes. Therefore, it can be handy to know some tools for the inspection of talloc memory usage. Talloc log and abort We have already encountered the abort function in section Dynamic type system. In that case it was used when a type mismatch was detected. However, talloc calls this abort function in several more situations: o when the provided pointer is not a valid talloc context, o when the meta data is invalid - probably due to memory corruption, o and when an access after free is detected. The third one is probably the most interesting. It can help us with detecting an attempt to double-free a context or any other manipulation with it via talloc functions (using it as a parent, stealing it, etc.). Before the context is freed talloc sets a flag in the meta data. This is then used to detect the access after free. It basically works on the assumption that the memory stays unchanged (at least for a while) even when it is properly deallocated. This will work even if the memory is filled with the value specified in TALLOC_FREE_FILL environment variable, because it fills only the data part and leaves the meta data intact. Apart from the abort function, talloc uses a log function to provide additional information to the aforementioned violations. To enable logging we shall set the log function with one of: o talloc_set_log_fn() o talloc_set_log_stderr() The following code is a sample output of accessing a context after it has been freed: talloc_set_log_stderr(); TALLOC_CTX *ctx = talloc_new(NULL); talloc_free(ctx); talloc_free(ctx); results in: talloc: access after free error - first free may be at ../src/main.c:55 Bad talloc magic value - access after free Another example is an invalid context: talloc_set_log_stderr(); TALLOC_CTX *ctx = talloc_new(NULL); char *str = strdup("not a talloc context"); talloc_steal(ctx, str); results in: Bad talloc magic value - unknown value Memory usage reports Talloc can print reports of memory usage of a specified talloc context to a file (to stdout or stderr). The report can be simple or full. The simple report provides information only about the context itself and its direct descendants. The full report goes recursively through the entire context tree. See: o talloc_report() o talloc_report_full() We will use the following code to retrieve the sample report: struct foo { char *str; }; TALLOC_CTX *ctx = talloc_new(NULL); char *str = talloc_strdup(ctx, "my string"); struct foo *foo = talloc_zero(ctx, struct foo); foo->str = talloc_strdup(foo, "I am Foo"); char *str2 = talloc_strdup(foo, "Foo is my parent"); /* print full report */ talloc_report_full(ctx, stdout); It will print a full report of ctx to the standard output. The message should be similar to: full talloc report on 'talloc_new: ../src/main.c:82' (total 46 bytes in 5 blocks) struct foo contains 34 bytes in 3 blocks (ref 0) 0x1495130 Foo is my parent contains 17 bytes in 1 blocks (ref 0) 0x1495200 I am Foo contains 9 bytes in 1 blocks (ref 0) 0x1495190 my string contains 10 bytes in 1 blocks (ref 0) 0x14950c0 We can notice in this report that something is wrong with the context containing struct foo. We know that the structure has only one string element. However, we can see in the report that it has two children. This indicates that we have either violated the memory hierarchy or forgotten to free it as temporary data. Looking into the code, we can see that 'Foo is my parent' should be attached to ctx. See also: o talloc_enable_null_tracking() o talloc_disable_null_tracking() o talloc_enable_leak_report() o talloc_enable_leak_report_full() Version 2.0 Tue Jun 17 2014 libtalloc_debugging(3)
All times are GMT -4. The time now is 06:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy