Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Parsing struct memory? Date: Thu, 16 Mar 2017 19:14:59 -0700 Organization: None to speak of Lines: 30 Message-ID: References: <62daf505-60e2-4dd5-b2c7-c619085dd548@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="a62e3c498ac96524fc545ef94a9038ec"; logging-data="3057"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+w+GBhVXzoiEg82eWzNPh2" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:1vC9EQ0MNzU4mSPe6d+3eju3pqQ= sha1:vJfOf0s8/Z5VOukVn2SuicUtw/Q= Xref: csiph.com comp.lang.c:106310 Thiago Adams writes: > Having some struct; > > struct { > char c; > void* p; > double d; > }; > > Is it possible to parse it just knowing each type? > Something similar of var_arg but for structs. > > char c = arg(pointer, char); > void* p = arg(pointer, void*); > double d = arg(pointer, double); Not easily or portably. Once upon a time, I worked on a project that parsed C declarations to generate C code that would print out the sizes and offsets of all the members of all the structures in a set of C headers. The intent was to use that information to generate code that could access struct members by name at run time from raw data transmitted to a system with a possibly different architecture. (I don't have any of the source code.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"