Re: Same-name typedefS in separate translation units



On Mon, 2 Feb 2009 23:44:24 -0600 (CST), Andrew Talbot
<t7dy4p902@xxxxxxxxxxxxxx> wrote:

I have two files with different struct types that have the same name as each
other, and both are wrapped in typedefS with identical names as follows
(simplified).

file1.c:

typedef struct s S;

struct s { char *pc; int n; };
....


file2.c:

typedef struct s S;

struct s { char *pc; long n; };
<snip>
I believe that the struct declarations do not inherently conflict in this
case (see http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1226.pdf), so if
the variable "st", in file2.c, were instead declared as having type
struct s *, it would use the local version of "s". But the question is do
the typedefS conflict and spoil this defined behavior, or does their
apparent "incomplete type" nature prevent that?

The 'incomplete' (here, just forward) type doesn't matter. ALL type
declarations are local to a translation unit at most, so this is fine
for compilation. Objects/variables and functions declared with
external linkage do have 'global'=program scope, but formally linkage
is not the same thing as declaration, and types have no linkage.
Although the standard intentionally doesn't talk about implementation,
this actually reflects the important implementation difference between
compiler symbols and linker symbols, which are related but decidedly
not the same thing.

However, if you want to (be able to) debug the resulting program with
a symbolic (i.e. half-decent) debugger, which is outside the scope of
the C standard, THAT may very well have problems with this.
--
comp.lang.c.moderated - moderation address: clcm@xxxxxxxxxxxx -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
.



Relevant Pages

  • Re: long long problem
    ... > I'm having trouble with unsigned long long declarations on my SCO unix ... > 7.1.1 compiler. ... > typedef struct { ... C only requires support for bitfields of types signed int, plain int, ...
    (comp.lang.c)
  • Re: Same-name typedefS in separate translation units
    ... typedef struct s S; ... void fn ... I believe that the struct declarations do not inherently conflict in this ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)
  • how to call this C function in C#
    ... I'm trying to call a C function whose header file looks like this: ... and the only declarations are ... typedef struct AB AB; ... typedef int; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to handle display 128 bit integer (signed and unsigned)
    ... This can be awkward on big-endian systems, ... numbered in the "wrong" order (the most-significant element will be ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)
  • How to handle display 128 bit integer (signed and unsigned)
    ... and so the conversion character of printf. ... I just have not idea about how to display them. ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)