Re: [Tinycc-devel] defined twice error commented out

2015-10-30 Thread Michael Matz
Hi,

On Thu, 29 Oct 2015, grischka wrote:

> Michael Matz wrote:
> > ... In C it's not allowed to have two definitions of the same non-static
> > symbol, simple as that.  It's not only for when initialized with different
> > values or the like; it's undefined no matter what.
> 
> Maybe it isn't that clear.  See below from the c99 draft, in particular
> the word "tentative".

Yes, but multiple tentative definitions are only allowed inside one 
translation unit, where they then collapse into one definition equivalent 
to one initialized by 0.  When multiple such translation units are 
involved then 6.9#5 comes into play:

5  An external definition is an external declaration that is also a 
   definition of a function (other than an inline definition) or an 
   object. If an identifier declared with external linkage is used in an 
   expression (other than as part of the operand of a sizeof operator 
   whose result is an integer constant), somewhere in the entire program 
   there shall be exactly one external definition for the identifier; 
   otherwise, there shall be no more than one.

In particular exactly one definition if the identifier is used; and not 
more than one when it's unused.


Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] defined twice error commented out

2015-10-29 Thread Sergey Korshunoff
Hi -gr
> TCC already has that flag: -fcommon
Thanks!

> Also, your patch does wrong things
Yes, It looks like a more work needed.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] defined twice error commented out

2015-10-29 Thread grischka

Michael Matz wrote:
... In C it's not 
allowed to have two definitions of the same non-static symbol, simple as 
that.  It's not only for when initialized with different values or the 
like; it's undefined no matter what.


Maybe it isn't that clear.  See below from the c99 draft, in particular
the word "tentative".

Anyway, it's not that TCC's behavior in that area couldn't be better.
Whether or not -f(no-)common should make a difference may be arguable
too.

-- gr



6.9.2 External object definitions

Semantics

1 If the declaration of an identifier for an object has file scope
  and an initializer, the declaration is an external definition for
  the identifier.

2 A declaration of an identifier for an object that has file scope
  without an initializer, and without a storage-class specifier or
  with the storage-class specifier static, constitutes a tentative
  definition. If a translation unit contains one or more tentative
  definitions for an identifier, and the translation unit contains
  no external definition for that identifier, then the behavior is
  exactly as if the translation unit contains a file scope declaration
  of that identifier, with the composite type as of the end of the
  translation unit, with an initializer equal to 0.

3 If the declaration of an identifier for an object is a tentative
  definition and has internal linkage, the declared type shall not
  be an incomplete type.

4 EXAMPLE 1

int i1 = 1; // definition, external linkage
static int i2 = 2;  // definition, internal linkage
extern int i3 = 3;  // definition, external linkage
int i4; // tentative definition, external linkage
static int i5;  // tentative definition, internal linkage

int i1; // valid tentative definition, refers to previous
int i2; // 6.2.2 renders undefined, linkage disagreement
int i3; // valid tentative definition, refers to previous
int i4; // valid tentative definition, refers to previous
int i5; // 6.2.2 renders undefined, linkage disagreement

extern int i1; // refers to previous, whose linkage is external
extern int i2; // refers to previous, whose linkage is internal
extern int i3; // refers to previous, whose linkage is external
extern int i4; // refers to previous, whose linkage is external
extern int i5; // refers to previous, whose linkage is internal

5 EXAMPLE 2

If at the end of the translation unit containing
int i[];
the array i still has incomplete type, the implicit initializer causes
it to have one element, which is set to zero on program startup.




___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] defined twice error commented out

2015-10-29 Thread Stephan Beal
On Thu, Oct 29, 2015 at 8:23 AM, Sergey Korshunoff  wrote:

> > Removing a valid warning is never a goid idea long-term.
> A tcc message was: Error And this condition is an error only if an
> initialization with diffenet values asked. In other cases it can be
> only warning. And there must be a flag to supress it
>


(finally off the train, so i can type properly...)

To be clear: i am not a tcc dev and have no authority here. However,
experience tells me that a system which does not warn when it should leads
to more errors long-term (e.g. MSVC 6 does not warn for many conditions
which gcc rightfully considers fatal, e.g. forgetting to return a value
from a non-void function). Duplicate definitions are such a case. Even if
they are identical, the fact that they're being included twice likely
indicates a code structure problem and "should" emit a warning unless (as
you say) they are actively suppressed. Programmers very much rely on their
compilers to point out (potential) problems, with more aggressive/less
lenient generally being more useful than less aggressive/more lenient.

Again, that's just my $0.02, not an authoritative answer.

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] defined twice error commented out

2015-10-29 Thread Sergey Korshunoff
Hi Stephan Beal
> That is not valid logic for justifying the silencing of a fatal code condition
But a condition is not fatal

>> What a solution can be:
What you can say about a right way?

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] defined twice error commented out

2015-10-29 Thread Stephan Beal
On Oct 29, 2015 07:57, "Sergey Korshunoff"  wrote:
>
> Hi Stephan Beal
> > That is not valid logic for justifying the silencing of a fatal code
condition
> But a condition is not fatal

Try linking duplicate definitions. They are fatal, by definition. It's
called the ODR -  One Definition Rule.

>
> >> What a solution can be:
> What you can say about a right way?

Leaving it how it was until a consensus can be reached about a solution.
Removing a valid warning is never a goid idea long-term.

- stephan
Sent from a mobile device, possibly from bed. Please excuse brevity, typos,
and top-posting.
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] defined twice error commented out

2015-10-29 Thread Sergey Korshunoff
> Removing a valid warning is never a goid idea long-term.
A tcc message was: Error And this condition is an error only if an
initialization with diffenet values asked. In other cases it can be
only warning. And there must be a flag to supress it

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] defined twice error commented out

2015-10-29 Thread grischka

Sergey Korshunoff wrote:

Removing a valid warning is never a goid idea long-term.

A tcc message was: Error And this condition is an error only if an
initialization with diffenet values asked. In other cases it can be
only warning. And there must be a flag to supress it


TCC already has that flag: -fcommon

Also, your patch does wrong things:

Example:

foo.c:
int xxx = 12;
int main() { printf("--> %d\n", xxx); return 0; }
bar.c:
int xxx = 34;
tcc foo.c bar.c && ./a.out
--> 12

This is wrong.  Result must be "error: xxx defined twice"

Another example:

foo.c:
int xxx;
int main() { printf("--> %d\n", xxx); return 0; }
bar.c:
int xxx = 34;
tcc foo.c bar.c && ./a.out
--> 0

Wrong too.  Result must be "--> 34"

-- gr


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] defined twice error commented out

2015-10-28 Thread Michael Matz
Hi,

On Sun, 25 Oct 2015, Sergey Korshunoff wrote:

> Hi! Commented out a tcc_error_noabort("'%s' defined twice"... on mob
> gcc-3.4.6 don't give such error by default
> example file1.c
>   char __version_303_;
>   void func1() {}
> example file2.c
>   char __version_303_;
>   void func2() {}
>   int main() { return 0; }
> I think there must be a switch to supress such message as minimum

No, please keep the message.  That GNU ld doesn't error out in this case 
is a side-effect of GCC using common symbols.  If it wouldn't then also ld 
would error.  Try compiling the above with -fno-common and GCC and you'll 
see it.

It would also error out if you would initialize both definitions.  So, 
please revert.


Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] defined twice error commented out

2015-10-28 Thread Sergey Korshunoff
Hi Michael Matz

> No, please keep the message
That was a quick fix for the problem.

> So, please revert.
Revert is not a solition. If gcc don't complain, than a tcc must not
complain too.
What a solution can be:
 * a some switch to disable this error message (a simple solution)
How to name it?

 * producing a common symbols by tcc too. Can tcc do this?

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] defined twice error commented out

2015-10-24 Thread Sergey Korshunoff
Hi! Commented out a tcc_error_noabort("'%s' defined twice"... on mob
gcc-3.4.6 don't give such error by default
example file1.c
  char __version_303_;
  void func1() {}
example file2.c
  char __version_303_;
  void func2() {}
  int main() { return 0; }
I think there must be a switch to supress such message as minimum

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel