| delorie.com/archives/browse.cgi | search |
| Message-ID: | <3E2726AB.9030704@earthlink.net> |
| From: | Martin Ambuhl <mambuhl AT earthlink DOT net> |
| User-Agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 |
| X-Accept-Language: | en-us, en, de, fr, ru, el, zh |
| MIME-Version: | 1.0 |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: sizeof(struct x) doesn't compile -- how to do it ? |
| References: | <b07318$3eg$1 AT news DOT online DOT de> |
| Lines: | 49 |
| Date: | Thu, 16 Jan 2003 21:40:16 GMT |
| NNTP-Posting-Host: | 67.210.12.88 |
| X-Complaints-To: | abuse AT earthlink DOT net |
| X-Trace: | newsread2.prod.itd.earthlink.net 1042753216 67.210.12.88 (Thu, 16 Jan 2003 13:40:16 PST) |
| NNTP-Posting-Date: | Thu, 16 Jan 2003 13:40:16 PST |
| Organization: | EarthLink Inc. -- http://www.EarthLink.net |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Lars Hansen wrote:
> #include "stdlib.h"
>
> struct x
> {
> double x;
> };
>
> int main()
> {
> x* n=malloc(2*sizeof(struct x));
> }
>
>
> produces the following compiler error message:
>
> test.c: In function `main':
> test.c:10: `x' undeclared (first use in this function)
> test.c:10: (Each undeclared identifier is reported only once
> test.c:10: for each function it appears in.)
> test.c:10: `n' undeclared (first use in this function)
>
>
> So how do I get the size of structs with djgpp?
#include <stdlib.h>
struct x
{
double x;
};
int main()
{
struct x *n = malloc(2 * sizeof(struct x));
}
>
> And also: if i have an array of a struct with several elements how can i know
> at which byte an element of the nth struct is in that array with djgpp (eg
> after writing a struct array to file and then loading this data without
> knowing how to "synchronize" djgpps compiler struct array generation and
> saving and an other compilers array struct generation and loading means one
> best knows the byte position (and length))
Lookup offsetof()
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |