pre-ansi declarations

c

    Sponsored Links

    Next

  • 1. [OT] Implementing my own memcpy
    In article < XXXX@XXXXX.COM >, CBFalconer wrote: > Nils Weller wrote: >> Nils Weller wrote: >> >>> rc = read(buf, sizeof buf - 1, fd); >> >> Of course I had to goof this one! >> >> rc = read(fd, buf, sizeof buf - 1); > > I have no idea what it goes with, because your previous article was > much too long to read. :-) However, you have still goofed, because > there is no such standard function as 'read'. Look up fread, which > IS portable. And nobody claimed that read() is a standard C function. I explicitly commented the code as being Unix-specific in the previous, too long post. Moreover, the macro that triggered this sub-thread has also been pointed out to be Unix-specific, and there has been some talk about Unix kernel implementation and compatibility system software. Perhaps an OT tag was missing, but I think it is clear that we aren't talking about standard C anymore. -- Nils R. Weller, Bremen / Germany My real email address is ``nils<at>gnulinux<dot>nl'' ... but I'm not speaking for the Software Libre Foundation!
  • 2. K&R3?
    Hello, does anyone have a clue when/if we might see K&R3? K&R2 is starting to feel a little dusty... Can anyone recommend any other good printed reference material? Regards, Ralph
  • 3. ANSI C Compilation linking problem
    I get an error when the compilator tries to link the object files of my program. I have the files group.h and group.c that use a struct define in logic.h and two fonctions define in logic.c. The program compile group.o fine, but when trying to link, I get an error in group.h saying that a struct that is defined in logic.h cannot be found. Include logic.h is explicitly call in group.h because it used an instance of that struct. What I dont understand is how, when the program compile, it is able to find the reference to the struct in logic, but when he tries to link, he does not find it anymore. If I take all the code from logic.h and logic.c and I copy it in group.h and group.c respectively, it links fine. I don't know what else to try, any ideas is welcome. Benoit Grimard
  • 4. some very simple increment/decremant operator question
    hello, I am confused with following programs snippet code about how the answer comes? statement/expression is evaluated? 1) int i=5; i=i++*i++*i++*i++; why the answer is not 5*6*7*8= 1680 but its 629? 2) int val=2; val = - --val- val--- --val; how to evaluate this? 3) int i=5; printf("%d %d %d %d %d\n",++i,i++,i++,i++,++i); why ans is not 6 6 7 7 10 but its 7 6 6 6 6? regards, rahul.

pre-ansi declarations

Postby j0mbolar » Thu, 09 Feb 2006 10:41:52 GMT

Which sections in the standard mandate that 'foo' below does
not qualify as a function that includes a prototype:

void foo(a)
 char *a;
{
    do_something(a);
}

int main(void)
{
    foo();
    return 0;
}



also, under 6.11.2 of c99, how is it possible
to declare a file scope object with internal linkage
without using 'static'?


Re: pre-ansi declarations

Postby Keith Thompson » Thu, 09 Feb 2006 11:04:59 GMT

"j0mbolar" < XXXX@XXXXX.COM > writes:

Probably the definition of "function prototype" in 6.2.1p2:

    A _function prototype_ is a declaration of a function that
    declares the types of its parameters.

The *definition* of foo() declares the type of a; the *declaration*
doesn't.


I don't know.  Anybody else?

-- 
Keith Thompson (The_Other_Keith)  XXXX@XXXXX.COM   < http://www.**--****.com/ ~kst>
San Diego Supercomputer Center             <*>  < http://www.**--****.com/ ~kst>
We must do something.  This is something.  Therefore, we must do this.

Re: pre-ansi declarations

Postby j0mbolar » Thu, 09 Feb 2006 11:20:17 GMT




So where default argument promotions do not apply,
do pre-ansi compilers infer the type in the above example
from 'a', so that they know it is a 'pointer to char'?


Re: pre-ansi declarations

Postby Keith Thompson » Thu, 09 Feb 2006 11:51:02 GMT

"j0mbolar" < XXXX@XXXXX.COM > writes:



Within the function, the declaration of a is visible, so the compiler
knows it's a char*.

For a call, the compiler doesn't know what type of argument the
function expects, so it's up to the caller to pass the right type.
It's similar to what happens with printf-like functions.

-- 
Keith Thompson (The_Other_Keith)  XXXX@XXXXX.COM   < http://www.**--****.com/ ~kst>
San Diego Supercomputer Center             <*>  < http://www.**--****.com/ ~kst>
We must do something.  This is something.  Therefore, we must do this.

Re: pre-ansi declarations

Postby Eric Sosman » Fri, 10 Feb 2006 00:57:04 GMT


j0mbolar wrote On 02/07/06 20:41,:

    Perhaps 6.11.2 is referring to the situation described
in 6.2.2/4:

	/* at file scope: */
	static int x;   /* internal linkage */
	...
	extern int x;   /* internal linkage, obscolescent(?) */

-- 
 XXXX@XXXXX.COM 


Re: pre-ansi declarations

Postby j0mbolar » Fri, 10 Feb 2006 06:01:45 GMT




What would make that obsolescent? And technically,
this would involve the use of 'static' in making it
have internal linkage. It is just that the latter declaration
does not inhibit the former's meaning.


Re: pre-ansi declarations

Postby j0mbolar » Fri, 10 Feb 2006 06:05:20 GMT




I meant to set follow-ups to comp.std.c

What do the committee members in comp.std.c
have to say about this?


Re: pre-ansi declarations

Postby Antoine Leca » Fri, 10 Feb 2006 23:39:29 GMT



Can you elaborate?

If you mean
    static int x;
    int x;
I read 6.2.2p5, 2nd sentence as making x of external linkage, and the
combination of both lines is UB by 6.2.2p7.

This text is unchanged since C89 (I thought a DR had added something, so
checked, and turned empty.)


Antoine


Re: pre-ansi declarations

Postby Antoine Leca » Fri, 10 Feb 2006 23:41:47 GMT


j0mbolar va escriure:

What: the Standard, the very 6.11.2.

Why: because when you are looking only at the second line (arbitrarily far
from the first), you do not immediately notice that the identifier is not
visible outside this translation unit.

Making this obsolescent is (was really) a free card for the committee to
revoke such a possibility in the future. It is also a strong hint the above
is "bad style."


Antoine


Re: pre-ansi declarations

Postby kuyper » Sat, 11 Feb 2006 00:15:27 GMT





You should be aware that the following counts as a declaration of
foo():


while everything from here on in is only part of the definition of
foo(); it's not part of the declaration.
A declaration that is only a declaration, and not a definition, could
be present in one translation unit, while the actual definition of the
function might be in an entirely different translation unit.


No; they handled such code in pretty much the same way as it's
currently handled. The definition of 'a' that is provided as part of
the definition of foo() has significance only inside the definition of
foo(); it has no effect on the interpretation of calls to foo(). If the
promoted type of an argument is incompatible with the actual type of
the corresponding parameter, you've got trouble; there's no implicit
conversion to the specified type, because in the absence of a
prototype, there is no specified type. There's also no mandatory
diagnostic to warn you of the problem. That's why prototypes were
invented.


Similar Threads:

1.pre-ansi declarations

Eric Sosman wrote:
> j0mbolar wrote On 02/07/06 20:41,:
> > Which sections in the standard mandate that 'foo' below does
> > not qualify as a function that includes a prototype:
> >
> > void foo(a)
> >  char *a;
> > {
> >     do_something(a);
> > }
> >
> > int main(void)
> > {
> >     foo();
> >     return 0;
> > }
> >
> >
> >
> > also, under 6.11.2 of c99, how is it possible
> > to declare a file scope object with internal linkage
> > without using 'static'?
>
>     Perhaps 6.11.2 is referring to the situation described
> in 6.2.2/4:
>
> 	/* at file scope: */
> 	static int x;   /* internal linkage */
> 	...
> 	extern int x;   /* internal linkage, obscolescent(?) */
>

I meant to set follow-ups to comp.std.c

What do the committee members in comp.std.c
have to say about this?

2.[ANNOUNCE] wxAda (pre-pre-pre-pre-release)

Hi,

Just thought I'd post a little note about the status of the project. I
have uploaded the source to Tigris. This is not complete and I have
stalled. I have recently stumbled across major blocks which I need help
with. Or if somebody wants to take over leading development, I have no
problem with that; my future with wxAda isn't too clear to me at the
moment.

The source isn't in the best way, but it does build with wxWidgets
2.6.3 and does provide some functionality.

Please feel free to look over the project and see what can be done.

Thanks,
Luke.

3.wxAda (pre-pre-pre-pre-release)

4.pre ANSI code and writable-strings?

char *s = "Hello";
s[0] = 'J';
puts(s);

might print "Jello" in a pre-ANSI compiler - is the behaviour of this 
program undefined in any pre-ANSI compiler - or would it always have printed 
"Jello" with a pre-ANSI compiler?
In gcc with the "writable-strings" option this program prints
Jello
If there were more than one semantics for what this progran did under a 
pre-ANSI compiler, which semantics were chosen by gcc for the 
"writable-strings" option, and for what reason?



5.Pre-ANSI C functions and .NET browse information symbols

I need to compile a library of C code with pre-ANSI C functions using MS 
.NET 2003. The functions are declared something like this:

int myFunction(p)
double p;
{
  int x;
  code here...
  return x;
}

The compilation proceeds without a glitch but when I tell .NET to build 
browse information for the functions, it seems not to include the pre-ANSI 
functions in browse information.

I could manually make the functions ANSI compliant by changing the code but 
there are 75+ functions. This seems to work for a few functions that I have 
altered. Is there a switch that tells .NET that the functions are pre-ANSI 
style so that it can build the browse information correctly or some other 
way to get the functions into the browse information?

Thanks,
RK


6. Harbour ANSI C sprintf() for ANSI SQL.

7. maxplusII error: a deferred constant declaration without a full declaration is not supported

8. conflicting types or implicit declaration or incompatible implicit declaration



Return to c

 

Who is online

Users browsing this forum: No registered users and 52 guest