Array of pointers to arrays? 
Author Message
 Array of pointers to arrays?

Quote:

>> I think you are making an assumption (perhaps a correct one) that ...



Quote:
>Fair enough - how else might you interpret it?

The way in which one gets the method you suggested. :-)

In particular, if we are allowed to "count up" the strings first,
we can create an auxiliary array ("foo" in your example) and then
define the second array ("bar") of pointers that point to places
within the first.

The interpretation in which this is impossible amounts to the
equivalent of saying, e.g.:

    "I want to write some sort of C code that can #include a
    header containing double-quoted text that will be placed
    into a buffer and then also define an array of pointers
    that point into the buffer"

i.e.:

    #define SOME_WEIRD_MACRO(argument) some_expansion
    #include "the_strings.h"

But there is no definition for SOME_WEIRD_MACRO that will achieve
this goal, because we do not get a chance to count up the strings
and thus define two separate objects, one containing the text and
the other the pointers.  (We can still write a program that reads
"the_strings.h" and creates a new translation unit, of course, but
here our program will do the counting.)

Quote:
>But, in my (flawed) example above, foo is not static. Is

>int a;
>static int *b = &a;

>legal? I don't think so.

It is if "a" has static duration.  I added the "static" keyword
to make it clear that, in my version, it did indeed have static
duration.

In other words:

    /* translationunit.c */
    int a;
    static int *b = &a; /* OK -- "a" has static duration */
    void f(void) {
        int a;
        static int *b = &a; /* not OK, and generally fails */
    }

Quote:
>Actually, I think the principal problem here is that we have not been
>given the opportunity to offer better solutions involving, perhaps,
>dynamic data structures, because the OP has phrased his question in such
>a way that we don't know the real problem he's trying to solve. *Why*
>has he placed these seemingly arbitrary restraints on the design?

Indeed.  With the context of the specified requirements, however,
we can get at least very close.
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)





Sat, 05 Feb 2005 20:50:37 GMT  
 Array of pointers to arrays?

Quote:

> Agreed, it's legal, but I've understood that void-casting non-void
> functions like this is (or was) considered "good form".  If not, I'll
> be very happy to stop doing it since it does (IMO) adversely impact
> the readability of the code.

There's a program called lint (a source checker that picks up likely bugs)
that complained  whenever return values were unused. For user-defined
functions this is maybe ok, but it also complains every time you printf()ed
without a void cast. The consensus seems to be not to make lint happy.


Sun, 06 Feb 2005 05:20:58 GMT  
 Array of pointers to arrays?
Thanks to all of you for helping me clarify my thinking
about this question.

Regards,
Charles Sullivan



Mon, 07 Feb 2005 09:24:28 GMT  
 Array of pointers to arrays?
in comp.lang.c i read:

Quote:

>> Agreed, it's legal, but I've understood that void-casting non-void
>> functions like this is (or was) considered "good form".  If not, I'll
>> be very happy to stop doing it since it does (IMO) adversely impact
>> the readability of the code.

don't ignore return values.

Quote:
>There's a program called lint (a source checker that picks up likely bugs)
>that complained  whenever return values were unused. For user-defined
>functions this is maybe ok, but it also complains every time you printf()ed
>without a void cast. The consensus seems to be not to make lint happy.

so you just blithely continue even if the printf failed?  wow.  that might
be acceptable for diagnostic or lightly informative output, but, well, wow!

--
bringing you boring signatures for 17 years



Mon, 07 Feb 2005 17:50:53 GMT  
 
 [ 19 post ]  Go to page: [1] [2]

 Relevant Pages 
 

 
Powered by phpBB® Forum Software