Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.misc > #2221
| From | "James Harris" <james.harris.1@gmail.com> |
|---|---|
| Newsgroups | comp.lang.misc |
| Subject | Re: A good subset of C |
| Date | 2014-05-08 10:14 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <lkfht2$k2p$1@dont-email.me> (permalink) |
| References | (1 earlier) <op.xfdw11vx6zenlw@localhost> <lk8nrc$ov4$1@dont-email.me> <op.xfesqctt6zenlw@localhost> <lkd3fo$2mv$1@dont-email.me> <op.xfiic4pj6zenlw@localhost> |
"Rod Pemberton" <dont_use_email@xnothavet.cqm> wrote in message news:op.xfiic4pj6zenlw@localhost... ... >> What might header source.h contain? Here are two possible types of >> information: >> >> 1. Integer constants. For example, EOF in stdio.h. >> 2. Structs. For example, struct timespec in time.h. >> > > function prototypes, structs, unions, enums, #defines, macros, ... Function prototypes are an especially good example. >> Header files are a poor mechanism because there is no guarantee that the >> header used when the caller is compiled is the same header that was used >> when the callee is compiled. But with some discipline they can be >> effective. > > Should a distinction be maded between a program which includes it's own > header file and a program which includes a C library header file? > > In one case, the source which uses those headers are compiled too, but > not for the other. The other is compiled as a library. Sorry, I didn't understand that point. >> I was trying to say that things like struct timespec would need to be >> communicated to a program that interfaces with time functions. > > So, you're planning to object-orient-ize that struct somehow? ;-) I see the smiley so know you are kidding but I cannot see the connection. I wasn't thinking of any object orientation issues here. If your comment is about me saying "communicated to a program that interfaces with" I was thinking only about info comminicated at compile time - nothing dynamic. >> If the caller wants to update field tv_nsec of a struct timespec it >> needs to know its offset and its type at compile time. > > Yes. > >> Without the header mechanism how could that info be made available >> to the calling module? > > Didn't we have some conversation on something like this at least once > before, i.e., in reference to passing structs and data over a network? If we did that sounds like a dynamic issue. The info in the header such as a struct layout is about compile time so is very static! As an example of a header communicating a structure layout consider compiling the following reference to a structure struct timespec *tp; tp->tv_nsec = 0; That might compile to mov [esi + 4], dword 0 The point is that to produce this code the offset (4 in this case) of the field from the pointer needs to be known at compile time. The header would supply the struct definition from which the compiler works out the offset. I suppose the offset (4) might be filled in a link or load time. Interesting! > It could query what fields the function expects, but I don't quickly > recognize how the code would decide what to put into the fields. > > I.e., some intelligence is involved here, which can be captured by the > code, but it's better if each side understands what to expect. E.g., > if the calling module expects to pass a struct of a certain format, an > integer, and a string, but the queried function says the struct has > more members, the string is the wrong size, etc how does the callee > fix that? Yes, C's header mechanism normally supplies the interface info so that they match... as long as the right header is used, that is! >> What about the EOF example, above? How would a caller which needed >> to know the value of EOF used by the standard IO functions know >> what value EOF had been set to? > > That one is more concrete. If the code was designed to support > different EOF values, then code could query the value the other side > is using and use that. If the code is compiled for a value > which is different, then the code isn't going to be compatible. I think this too is normally done at compile time so that, for example, if (retval == EOF) might compile to cmp eax, -1 where, in this case, I have used -1 for EOF. The specific value would have come from a header, probably stdio.h. > What's with the need for all the abstraction? Hard to answer that as I'm not sure that there is a lot of abstraction here (in the C header mechanism, that is). > Are you still working on object-oriented stuff? Umm, not in connection with this but, depending on what you mean, possibly. Might make an interesting topic for a separate thread...? James
Back to comp.lang.misc | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-05 08:47 +0100
Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-05 10:56 +0100
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-05 19:41 +0100
Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-05 21:08 +0100
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-05 21:58 +0100
Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-05 22:55 +0100
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-06 00:01 +0100
Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-06 00:44 +0100
Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-06 09:45 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-05 07:33 -0400
Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-05 19:14 +0100
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-05 20:12 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-05 18:57 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-07 11:55 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-07 19:04 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-08 10:14 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-08 07:35 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-08 16:22 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-09 16:45 -0400
Re: A good subset of C "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-05-10 09:04 +0200
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-10 16:30 -0400
Re: A good subset of C "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-05-11 11:59 +0200
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-11 11:06 -0400
Re: A good subset of C Kaz Kylheku <kaz@kylheku.com> - 2014-05-12 00:26 +0000
Re: A good subset of C "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-05-12 09:54 +0200
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-12 20:01 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-14 17:45 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-14 18:11 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-14 23:54 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-14 19:43 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-17 18:00 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-17 16:00 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-17 22:17 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-17 19:58 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-18 07:59 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-18 13:10 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-19 00:54 +0100
Re: A good subset of C Andy Walker <news@cuboid.co.uk> - 2014-05-15 01:31 +0100
Re: A good subset of C BGB <cr88192@hotmail.com> - 2014-05-14 23:43 -0500
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-17 18:38 +0100
Re: A good subset of C Ian Collins <ian-news@hotmail.com> - 2014-05-25 11:04 +1200
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-24 20:36 -0400
Re: A good subset of C Ian Collins <ian-news@hotmail.com> - 2014-05-25 12:53 +1200
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-24 21:34 -0400
Re: A good subset of C Ian Collins <ian-news@hotmail.com> - 2014-05-25 14:11 +1200
Re: A good subset of C Kaz Kylheku <kaz@kylheku.com> - 2014-05-25 06:47 +0000
Re: A good subset of C Kaz Kylheku <kaz@kylheku.com> - 2014-05-25 06:43 +0000
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-05 20:59 +0100
Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-05 22:28 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-05 18:57 -0400
Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-06 00:26 +0100
Re: A good subset of C George Neuner <gneuner2@comcast.net> - 2014-05-06 14:21 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-07 15:43 +0100
Re: A good subset of C George Neuner <gneuner2@comcast.net> - 2014-05-07 16:03 -0400
Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-07 21:31 +0100
Re: A good subset of C BGB <cr88192@hotmail.com> - 2014-05-07 15:41 -0500
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-05 18:46 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-06 00:42 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-06 06:48 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-07 15:40 +0100
Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-08 06:50 -0400
Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-08 15:43 +0100
Re: A good subset of C George Neuner <gneuner2@comcast.net> - 2014-05-08 14:41 -0400
Re: A good subset of C BGB <cr88192@hotmail.com> - 2014-05-05 19:08 -0500
csiph-web