Subject: Re: $root, prototypes etc.
From: Peter Flake (flake@co-design.com)
Date: Fri Mar 15 2002 - 22:04:20 PST
Kevin,
In spite of its supposed deficiency in the global namespace, C has been
more successful in the marketplace than languages which avoid this problem,
such as Ada or Modula-2, or even Java.
The reason for having prototypes in C is that compilation of each file is
separate, and the linker does not check the number and types of
arguments. In SystemVerilog, as in Verilog, the whole source is used for
compilation so the number and types of arguments can be checked by the
elaborator. Furthermore this avoids the need to use name mangling as the
means of applying overloading to a linker with a single namespace, if we
wanted to add overloading to SystemVerilog.
It is so incredibly tedious to write
extern void printf(char *, ...);
extern FILE *fopen(char *, ...);
etc.
that people write
#include <stdio.h>
instead.
Do we want to force users to create headers of all the global names they
will be using, and include them in every module? I don't.
Regards,
Peter.
At 10:06 AM 3/15/02 -0800, Kevin Cameron x3251 wrote:
>[Previous post - http://www.eda.org/vlog-pp/hm/0125.html
> - includes proposals]
>
>C programming uses a global namespace similar to $root for
>all routines. Originally it didn't use prototypes, you just
>found routines by their name at link time. That's fine as
>long as there isn't a lot of code, once you do have a lot
>of code you need to add checks to make sure that you are
>calling the right routine e.g. always include the routine
>prototype so that you get the declaring module checked
>against it and the the module using it has the same
>interface. C++ uses "name mangling" which transforms the
>simple name of the routine into one dependent on its
>parameter types so that their is no confusion about what
>code to call (and you can overload the routine).
>
>The addition of new data types and the $root namespace
>in SystemVerilog will lead to the same problems as seen
>in C programming. So in an effort to be preemptive I
>think we should add all the prototyping mechanisms now
>rather than later, and disallow "lazy" linkage from
>the start. This will also help with modular compilation
>and hence compiled IP/library reuse, and interfacing
>to foreign languages.
>
>Proposal:
>
>1. All items used from $root should be declared fully by
> prototype, or by forward reference before use, unless
> backward compatibility dictates otherwise.
>
>2. Add syntax:
>
> Tasks and functions without statements are considered
> prototypes.
>
> 'extern' before 'module' and 'interface' indicate a
> prototype and limit the contents to structural items
> and public methods - which should match the actual
> declaration if seen.
>
> Ellipsis "..." can be used when there is an unknown
> number of a arguments.
>
> 'extern' before an (unsized) variable declaration
> behaves as in "C".
>
>
>While we are not doing function/module overloading at
>the moment it may be necessary to do it in future
>(particularly for AMS) to make automatic configuration
>during elaboration possible - i.e. I'm not suggesting
>this stuff because I like excessive typing [ pun
>intended :-) ], it'll just make some other things
>easier later.
>
>Regards,
>Kev.
>
>
>--
>National Semiconductor
>2900 Semiconductor Drive, Mail Stop D3-500, Santa Clara, CA 95052-8090
This archive was generated by hypermail 2b28 : Sun Mar 17 2002 - 06:39:25 PST