Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Forward declarations ... the straw that broke the camel's back |
| Date | 2016-07-05 23:20 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <nlh8b0$7fh$1@dont-email.me> (permalink) |
| References | (5 earlier) <aba6efe2-9a39-4bc9-bc1d-e54f7ac62ea6@googlegroups.com> <nl3jsa$tua$1@dont-email.me> <5cc9d00d-1c3e-4a15-b633-d238280370f8@googlegroups.com> <nlh2cc$gmp$1@dont-email.me> <1290b31f-a68b-47c1-bd3e-6d4b56f7d935@googlegroups.com> |
On 05/07/16 22:32, Rick C. Hodgin wrote:
> On Tuesday, July 5, 2016 at 3:39:03 PM UTC-4, David Brown wrote:
>> On 30/06/16 19:30, Rick C. Hodgin wrote:
>>> On Thursday, June 30, 2016 at 1:11:48 PM UTC-4, Bart wrote:
>>>> On 30/06/2016 13:42, Rick C. Hodgin wrote:
>>>>> On Thursday, June 30, 2016 at 8:00:23 AM UTC-4, Ben Bacarisse wrote:
>>>>>> Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
>>>>>>> Types are a nuisance.
>>>>>>
>>>>>> Many people think quite the opposite. Types are a huge convenience...
>>>>>
>>>>> My only issue regarding types is that in C and C++ they must be declared
>>>>> before use, even if they're declared later on in the same source file,
>>>>> or in a later include file that's still in scope relative to the compile
>>>>> instance.
>>>>
>>>> Why would declaring types ahead of use be an issue?
>>>
>>> It's as I described in my OP.
>>>
>>> Because it requires that all things be declared ahead of use, as you have
>>> mentioned in this thread. Some master "all_structs.h" file with all of
>>> the types used throughout the system.
>>>
>>> I don't want that. I want to include the SVariable type in the variable.h
>>> header, along with its prototype definitions and other related declarations.
>>> Then in the variables.cpp are all the body functions. But since SVariable
>>> is a first class citizen in my project, other modules use it, such as
>>> SReport directly knows about the SVariable type, and SDatabase knows about
>>> the variable type. So now I've got other header files declaring references
>>> to the SVariable type, which by pointer isn't an issue, but if it's by non-
>>> pointer, then it's an issue.
>>>
>>
>> Maybe I am misunderstanding something here. It looks like you want to
>> be able to declare the type SVariable in a header file "svariable.h" and
>> its associated functions in "svariable.c". And you now want to be able
>> to use your SVariable types in all files, including the structure
>> definition of "SReport" in "sreport.h". So why not simply #include
>> "svariable.h" in "svariable.h" ?
>>
>> // File svariable.h
>> #ifndef SVARIABLE_H_
>> #define SVARIABLE_H_
>>
>> #include <stdint.h>
>> typedef struct {
>> uint32_t a32;
>> uint16_t a16;
>> uint8_t a8;
>> } SVariable;
>>
>> #endif // #ifndef SVARIABLE_H_
>>
>> // File sreport.h
>> #ifndef SREPORT_H_
>> #define SREPORT_H_
>>
>> #include <stdbool.h>
>> #include "svariable.h"
>> typedef struct {
>> SVariable var;
>> bool b;
>> } SReport;
>>
>> #endif // #ifndef SREPORT_H_
>>
>>
>> // File foo.c
>> #include "sreport.h"
>> SReport rep;
>>
>>
>> You are only ever declaring your types once (which you usually have to
>> do somewhere). If you have intertwined types with fields that are
>> pointers to each other, then they are so closely related that it is
>> usually natural to put them in the same header.
>
> That's the C way of doing things.
This is a C newsgroup, and your question/complaint/issue was the trouble
you were having in writing this sort of thing in C. So a C way of doing
it is a pretty good start.
> I don't want that. It's not a good
> solution in my opinion.
That's not a justification.
> I also don't want to #include something, but
> would rather import it, and then have it be of a particular form which
> completely handles everything it needs internally.
If you want some sort of modules, with an "import" rather than an
"#include", then that's not a bad idea for a new language - it is widely
considered to be a missing feature for C and C++. People are working on
them for C++, where compilation of headers is a serious time-waster
(unlike in C, where it is only noticeable problem in the minds of a few
people). But that does not change the situation here - it just makes
things a little more efficient if you have big files.
> I've added the
> ability in a function to automatically undef it if there's a dependency
> missing, so that if SReport is not present, then the related SReport
> features will automatically be excluded, without having to surround the
> code in an #ifdef / #endif block.
That sounds terrible, but of course that is merely my opinion.
>
> I'm trying to rethink programming, keeping what's good, and leaving
> what's bad, and making CAlive be more than just C or C++.
>
You make it sound like there is some clear distinction between "good"
and "bad" features of programming. Your CAlive project is highly
personal - it is about rethinking how /you/ want to program, keeping
what /you/ think is good, and discarding what /you/ think is bad.
That's fair enough - you are trying to make the perfect language for
/you/. But never forget that it is your personal language fitting your
personal ideas about programming - there is nothing objective about it.
> I basically want to include the things I need in my application one time,
> and in the exact program that's using them, then they are auto-handled
> internally.
If you were to write your code as a collection of .h and .c files, it
should not be a difficult issue to have a built system that sorts this
out automatically without moving an inch from standard C. A makefile
with a spot of scripting could easily allow the individual headers to be
collected and automatically #include'd into each C file when you do a build.
>
> I'm even considering doing away with the .h concept at all and creating
> a comparable single-source file which includes header definitions and
> source files and call it a .cai file (a CAlive import).
Add a call to "cproto" to the builder.
I am not saying that your ideas here are bad for your CAlive project -
if I were creating a new language, I would definitely have some kind of
proper module system rather than C's "copy-and-paste" pre-processor
includes. I would also probably allow file/global scope and namespace
scope (but /not/ local, block or function scope) functions, types and
data to be used before declaration.
So my point is not that they are bad ideas, but that C is not really as
bad as you seem to imagine here, and you can come quite close to your
desires with creative use of build scripts and/or code preprocssing,
without having to create a whole new language. You might get to program
closer to the way you want before CAlive is ready.
>
> That way you'll have .ca source files, and .cai import files. The
> syntax of the .cai file will allow either direct source code or library
> references without then having to add any linker settings.
>
> Best regards,
> Rick C. Hodgin
>
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-29 10:36 -0700
Re: Forward declarations ... the straw that broke the camel's back supercat@casperkitty.com - 2016-06-29 16:04 -0700
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-29 16:30 -0700
Re: Forward declarations ... the straw that broke the camel's back Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-06-29 19:52 -0700
Re: Forward declarations ... the straw that broke the camel's back Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-06-30 13:00 +0100
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-30 05:42 -0700
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-06-30 18:11 +0100
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-30 10:30 -0700
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-06-30 19:54 +0100
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-30 12:31 -0700
Re: Forward declarations ... the straw that broke the camel's back Ian Collins <ian-news@hotmail.com> - 2016-07-01 07:59 +1200
Re: Forward declarations ... the straw that broke the camel's back Gareth Owen <gwowen@gmail.com> - 2016-06-30 21:31 +0100
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-30 14:19 -0700
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-30 14:31 -0700
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-06-30 21:18 +0100
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-30 14:26 -0700
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-06-30 22:44 +0100
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-30 17:23 -0700
Re: Forward declarations ... the straw that broke the camel's back David Brown <david.brown@hesbynett.no> - 2016-07-05 21:38 +0200
Re: Forward declarations ... the straw that broke the camel's back Richard Heathfield <rjh@cpax.org.uk> - 2016-07-05 21:05 +0100
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-07-05 13:32 -0700
Re: Forward declarations ... the straw that broke the camel's back David Brown <david.brown@hesbynett.no> - 2016-07-05 23:20 +0200
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-07-05 14:25 -0700
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-07-05 16:14 -0700
Re: Forward declarations ... the straw that broke the camel's back David Brown <david.brown@hesbynett.no> - 2016-07-06 11:18 +0200
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-07-06 03:36 -0700
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-07-05 16:23 -0700
Re: Forward declarations ... the straw that broke the camel's back David Brown <david.brown@hesbynett.no> - 2016-07-06 11:29 +0200
Re: Forward declarations ... the straw that broke the camel's back Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-07-06 02:49 -0700
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-07-06 05:18 -0700
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-07-06 13:57 +0100
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-07-06 06:24 -0700
Re: Forward declarations ... the straw that broke the camel's back David Brown <david.brown@hesbynett.no> - 2016-07-06 15:22 +0200
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-07-06 07:12 -0700
Re: Forward declarations ... the straw that broke the camel's back Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-07-06 08:08 -0700
Re: Forward declarations ... the straw that broke the camel's back supercat@casperkitty.com - 2016-07-06 09:00 -0700
Re: Forward declarations ... the straw that broke the camel's back Ian Collins <ian-news@hotmail.com> - 2016-07-07 08:01 +1200
Re: Forward declarations ... the straw that broke the camel's back supercat@casperkitty.com - 2016-07-06 13:30 -0700
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-07-06 17:30 +0100
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-06-30 00:39 +0100
Re: Forward declarations ... the straw that broke the camel's back jacobnavia <jacob@jacob.remcomp.fr> - 2016-06-30 22:08 +0200
Re: Forward declarations ... the straw that broke the camel's back gordonb.h5sc5@burditt.org (Gordon Burditt) - 2016-06-29 20:52 -0500
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-29 19:00 -0700
Re: Forward declarations ... the straw that broke the camel's back Ian Collins <ian-news@hotmail.com> - 2016-06-30 16:06 +1200
Re: Forward declarations ... the straw that broke the camel's back Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-06-30 02:48 -0700
Re: Forward declarations ... the straw that broke the camel's back Ian Collins <ian-news@hotmail.com> - 2016-06-30 23:25 +1200
Re: Forward declarations ... the straw that broke the camel's back Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-06-30 04:39 -0700
Re: Forward declarations ... the straw that broke the camel's back jacobnavia <jacob@jacob.remcomp.fr> - 2016-06-30 21:50 +0200
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-06-30 06:49 -0700
Re: Forward declarations ... the straw that broke the camel's back jacobnavia <jacob@jacob.remcomp.fr> - 2016-06-30 22:23 +0200
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-07-04 10:43 -0700
Vaporware (Was: Forward declarations ... the straw that broke ...) gazelle@shell.xmission.com (Kenny McCormack) - 2016-07-04 17:59 +0000
Re: Forward declarations ... the straw that broke the camel's back Randy Howard <rhoward.mx@EverybodyUsesIt.com> - 2016-07-06 12:38 -0500
Re: Forward declarations ... the straw that broke the camel's back "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-07-06 11:38 -0700
Re: Forward declarations ... the straw that broke the camel's back Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-06-30 19:51 +0100
Re: Forward declarations ... the straw that broke the camel's back jacobnavia <jacob@jacob.remcomp.fr> - 2016-06-30 21:59 +0200
Re: Forward declarations ... the straw that broke the camel's back Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-07-01 01:05 -0700
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-06-30 11:32 +0100
Re: Forward declarations ... the straw that broke the camel's back Ian Collins <ian-news@hotmail.com> - 2016-06-30 23:23 +1200
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-06-30 14:28 +0100
Re: Forward declarations ... the straw that broke the camel's back supercat@casperkitty.com - 2016-06-30 08:24 -0700
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-06-30 16:56 +0100
Re: Forward declarations ... the straw that broke the camel's back jacobnavia <jacob@jacob.remcomp.fr> - 2016-06-30 22:17 +0200
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-06-30 22:22 +0100
Re: Forward declarations ... the straw that broke the camel's back jacobnavia <jacob@jacob.remcomp.fr> - 2016-07-01 08:25 +0200
Re: Forward declarations ... the straw that broke the camel's back BartC <bc@freeuk.com> - 2016-07-01 12:09 +0100
csiph-web