delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/17/18:45:19

From: "Anthony.Appleyard" <MCLSSAA2 AT fs2 DOT mt DOT umist DOT ac DOT uk>
Organization: Materials Science Centre
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>, DJGPP AT delorie DOT com
Date: Tue, 17 Mar 1998 15:09:34 GMT
Subject: Re: Clobbered
Reply-to: Anthony DOT Appleyard AT umist DOT ac DOT uk
CC: DJGPP AT delorie DOT com
Message-ID: <663C9241F5@fs2.mt.umist.ac.uk>

  Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:-
> Please post a minimal complete source that can be compiled and
> reproduces the warning about clobbering.

  This program when compiled with -O2:-

#include <stdio.h>
#include <setjmp.h>
int driveexists(char T){return T;}
int drive_is_empty(char T){return T;}
/*-----*/
main(int nargs,char**arg){
int i,n; char*T,*U=0; jmp_buf emacserror,*bad;
T=nargs>=2?arg[1]:".";
bad=&emacserror; if(setjmp(*bad)) exit(1);
n=strlen(T); for(i=0;i<n;i++) if(T[i]=='['?:T[i]==']') {T="."; break;}
if(*T) if(T[1]==':') if(!driveexists(*T)?:drive_is_empty(*T)?1:0) *T=0;
strcpy(U,T);}

  causes this warning:-

_.cc: In function `int main(int, char **)':
_.cc:7: warning: variable `char * T' might be clobbered by `longjmp' or `vfork'

  This program when compiled with -O2:-

#include <stdio.h>
#include <setjmp.h>
int driveexists(char T){return T;}
int drive_is_empty(char T){return T;}
/*-----*/
main(int nargs,char**arg){
int i,n; volatile char*T; char*U=0; jmp_buf emacserror,*bad;
T=nargs>=2?arg[1]:".";
bad=&emacserror; if(setjmp(*bad)) exit(1);
n=strlen(T); for(i=0;i<n;i++) if(T[i]=='['?:T[i]==']') {T="."; break;}
if(*T) if(T[1]==':') if(!driveexists(*T)?:drive_is_empty(*T)?1:0) *T=0;
strcpy(U,T);}

  with *T declared volatile causes these three warnings:-

_.cc: In function `int main(int, char **)':
_.cc:10: warning: passing `volatile char *' as argument 1 of
    `strlen(const char *)' discards volatile
_.cc:12: warning: passing `volatile char *' as argument 2 of
    `strcpy(char *, const char *)' discards volatile
_.cc:7: warning: variable `volatile char * T' might be clobbered by `longjmp'
    or `vfork'

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019