delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/12/18/01:31:43

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Radical NetSurfer <RadSurfer AT yahoo DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: PLEASE EXPLAIN v2.953
Date: Sat, 18 Dec 2004 01:21:07 -0500
Message-ID: <4tg7s0182f12t4dlbri2pdq2uqq6ausos7@4ax.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Organization: Velocity.Net
Cache-Post-Path: web.velocity.net!unknown AT 66-211-207-39 DOT velocity DOT net
X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/)
Lines: 165
X-Complaints-To: abuse AT newshosting DOT com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I am using:

c:\djgpp>gcc --version 
2.953

EXPLAIN PLEASE the problem with THIS snippet:

/* A Test for Short, and Unsigned Short */

#include <stdio.h>

int main(void) {

short ashort;
unsigned short ushort;

   ashort = -12345;
   ushort =  65432;

   printf("(signed) Short: %h\n", ashort);
   printf("Unsigned Short: %u\n", ushort);


return (0);
} //Main

c:\djgpp>gc s
GCC DJGPP 32-Bit
s.c: In function `main':
s.c:13: warning: unknown conversion type character 0xa in format
s.c:13: warning: too many arguments for format

Line 13 just happens to be:
   printf("(signed) Short: %h\n", ashort);

_IF_ however I change it to this:
   printf("(signed) Short: %i\n", ashort);

then THIS output occurs:

c:\djgpp>gc s
C:\djgpp>

In other words, *NO ERRORS* reported!

Running it we obtain:

C:\djgpp>s
(signed) Short: -12345
Unsigned Short: 65432

OK! all went well indeed!

***
*** The point here is: When was   %h  dropped? and WHY?
*** %i  is to be the substitute for  %h  ??
***

THIS NEXT EXAMPLE concerns  
                             signed/unsigned  longs
and their Hex outputs...


/* A Test for Short, and Unsigned Short 

   A Test for Long, and Unsigned Long

   12-17-04
*/

#include <stdio.h>

int main(void) {

short ashort;
unsigned short ushort;
long along;
unsigned long ulong;

   ashort = -12345;
   ushort =  65432;

   along = -12345678;
   ulong = 12345678;

   printf("[1] (signed) Short: %i\n", ashort);  //Works!
   printf("[2] Unsigned Short: %u\n", ushort);  //Works!

   printf("[3] (signed) Long: %D\n", along);    //Not recognized!
/*
s.c:26: warning: unknown conversion type character `D' in format
s.c:26: warning: too many arguments for format
*/

   printf("[4] Unsigned Long: %U\n", ulong);    //Not recognized!
/*
s.c:32: warning: unknown conversion type character `U' in format
s.c:32: warning: too many arguments for format
*/


   printf("[5] (signed) Long: %X\n", along);  //Displays Properly?
   printf("[6] (signed) Long: %X\n", ulong);  //Displays Properly?


   printf("[7] (signed) Long: %lX\n", along); 
/*
s.c:38: warning: unsigned int format, long unsigned int arg (arg 2)
works: notice that no 'l' is printed!
*/

   printf("[8] (signed) Long: %lX\n", ulong);
/*
s.c:39: warning: unsigned int format, long unsigned int arg (arg 2)
works: notice that no 'l' is printed!
*/

   printf("[ 9] (signed) Long: %ld\n", along);  //Displays Properly?
   printf("[10] (signed) Long: %lu\n", ulong);  //Displays Properly?

return (0);
} //Main

/*
c:\djgpp>s
[1] (signed) Short: -12345
[2] Unsigned Short: 65432
[3] (signed) Long: -12345678
[4] Unsigned Long: 12345678
[5] (signed) Long: FF439EB2     %X (unsigned)
[6] (signed) Long: BC614E         %X (signed) 
[7] (signed) Long: FF439EB2     ok, so where did the   %l  part go?
[8] (signed) Long: BC614E         ok, so where did the   %l  part go?
[ 9] (signed) Long: -12345678
[10] (signed) Long: 12345678
*/

USING  %lX  with 2.953 seems to cause DJGPP to cause EXTRANEOUS
GARBAGE to be output to the screen, and get this: from *OTHER* parts
of the program !!!!

What is this indicating?
Why does it happen?

What is the PROPER way to print Signed and Unsigned 
Shorts {16  bit}, Ints / Longs {32-bit} as Decimal and Hex
values without all these extraneous issues coming to the surface
in 2.953 ?

%ld works, but get this, according to  'libc.txt' which describes the
library functions (by category, etc.) and looking at  
   printf

there is *NO* sign of &h,  no sign of 'l' as a long modifier,
and the mention of D and U are, as plainly seen above, 
UNRECOGNIZED !!!

What have I missed here?

email: RadSurfer AT yahoo DOT com

THANKS for replying!



- Raw text -


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