Sponsored Content
Full Discussion: sizeof
Top Forums Programming sizeof Post 86307 by ramneek on Thursday 13th of October 2005 03:20:47 AM
Old 10-13-2005
man u havent under stand my problem

as you said that it return zero
the same result i too am getting

but i have read that sizeof can never ever return zero even if the class or structure is empty

if you remove the char from the structure the value of sizeof is 1
but when include the char[] then its value is zero
why?

thats was my question
 

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
ggstrlcpy(3)								GGI							      ggstrlcpy(3)

NAME
ggstrlcpy, ggstrlcat - size-bounded string copying and concatenation SYNOPSIS
#include <ggi/gg.h> size_t ggstrlcpy(char *dst, const char *src, size_t siz); size_t ggstrlcat(char *dst, const char *src, size_t siz); DESCRIPTION
The ggstrlcpy and ggstrlcat functions copy and concatenate strings respectively. They are designed to be safer, more consistent, and less error prone replacements for strncpy(3) and strncat(3). Unlike those functions, ggstrlcpy and ggstrlcat take the full size of the buffer (not just the length) and guarantee to NUL-terminate the result (as long as size is larger than 0 or, in the case of ggstrlcat, as long as there is at least one byte free in dst). Note that you should include a byte for the NUL in size. Also note that ggstrlcpy and ggstrlcat only operate on true C strings. This means that for ggstrlcpy src must be NUL-terminated and for ggstrlcat both src and dst must be NUL- terminated. The ggstrlcpy function copies up to siz - 1 characters from the NUL-terminated string src to dst, NUL-terminating the result. The ggstrlcat function appends the NUL-terminated string src to the end of dst. It will append at most siz - strlen(dst) - 1 bytes, NUL- terminating the result. RETURN VALUES
The ggstrlcpy and ggstrlcat functions return the total length of the string they tried to create. For ggstrlcpy that means the length of src. For ggstrlcat that means the initial length of dst plus the length of src. While this may seem somewhat confusing it was done to make truncation detection simple. Note however, that if ggstrlcat traverses size characters without finding a NUL, the length of the string is considered to be size and the destination string will not be NUL-terminated (since there was no space for the NUL). This keeps ggstrlcat from running off the end of a string. In practice this should not happen (as it means that either size is incorrect or that dst is not a proper C string). The check exists to prevent potential security problems in incorrect code. EXAMPLES
The following code fragment illustrates the simple case: char *s, *p, buf[BUFSIZ]; ... (void)ggstrlcpy(buf, s, sizeof(buf)); (void)ggstrlcat(buf, p, sizeof(buf)); To detect truncation, perhaps while building a pathname, something like the following might be used: char *dir, *file, pname[MAXPATHLEN]; ... if (ggstrlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) goto toolong; if (ggstrlcat(pname, file, sizeof(pname)) >= sizeof(pname)) goto toolong; Since we know how many characters we copied the first time, we can speed things up a bit by using a copy instead of an append: char *dir, *file, pname[MAXPATHLEN]; size_t n; ... n = ggstrlcpy(pname, dir, sizeof(pname)); if (n >= sizeof(pname)) goto toolong; if (ggstrlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n) goto toolong; However, one may question the validity of such optimizations, as they defeat the whole purpose of ggstrlcpy and ggstrlcat. SEE ALSO
snprintf(3) strncat(3) strncpy(3) HISTORY
strlcpy and strlcat first appeared in OpenBSD 2.4, then in NetBSD 1.4.3 and FreeBSD 3.3.0. ggstrlcpy and ggstrlcat has been added to libgg for portability. libgg-1.0.x 2005-08-26 ggstrlcpy(3)
All times are GMT -4. The time now is 11:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy