Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.compilers > #3349
| From | gah4 <gah4@u.washington.edu> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: C and Java, was Compilers :) |
| Date | 2023-01-29 21:39 -0800 |
| Organization | Compilers Central |
| Message-ID | <23-01-083@comp.compilers> (permalink) |
| References | (1 earlier) <23-01-007@comp.compilers> <23-01-051@comp.compilers> <23-01-053@comp.compilers> <23-01-054@comp.compilers> <23-01-077@comp.compilers> |
On Sunday, January 29, 2023 at 8:57:52 AM UTC-8, dave_th...@comcast.net wrote: > On Fri, 13 Jan 2023 12:39:41 -0800 (PST), gah4 <ga...@u.washington.edu> (I wrote) > > > Some time ago, I was trying to figure out if you could make a C compiler > > > that generated JVM code. I would run much closer to the C standard > > > than much C code does, especially regarding casting of pointers. > > > [So what did you conclude? I'd think C type casts would be hard to > > > turn into Java unless you made all of storage an opaque block. -John] > > Someone else might have thought about the "opaque block" method. > > But that wouldn't work if you wanted to call between Java and C. > > As well as I know it, C only requires assignment to work for > > pointers cast to (unsigned char *). And once they are cast, > > usually (though I suppose not always), it is done with memcpy(), > > or compared with memcmp(). > Only unsigned char is 100% guaranteed, but on all known systems today > signed char has no trap rep and also works and so does plain char. But if the standard says (unsigned char *), and it failed with other types, would it still be C? In any case, I would put all the complications into memcpy() and memcmp(). Assignments cast to (unsigned char *) could call memcpy(). Otherwise, they would be assumed to work. (snip) > > I didn't get as far as figuring out varargs functions, but someone > > must have done that, as System.out.format() works. > > You can call it with the usual different argument types, > > and it figures out everything. > Java's System.out.format -- and Java's varargs in general -- works > differently than C (at least C as practiced; the standard imposes > enough restrictions you probably _could_ implement it differently). > When Java calls a varargs method, the _caller_ silently creates an > array and fills it with the argument values, alll converted to the one > type specified in the definition (or compiled equivalent), and that > _array_ is actually passed along with the fixed args, in this case the > format string and possibly locale. For this case the one type is > java.lang.Object, which is the top-type for all class _and_ array(1) > instances in Java so they pass unchanged; any primitive value (int, > float, etc) is siliently converted to an instance of a builtin class > (java.lang.Integer, java.lang.Float, etc) by 'autoboxing'. As a result > the format method(2) just matches format specifiers to elements of > that array (remember each Java array instance knows its own length so > subscripting out of bounds traps). But also, Java didn't always do that automatically. > Or more simply, Java varargs is sugar for a homogenous array. I suppose, but it is a lot of sugar! Having to do the array creating, and all the conversions to fill the array is a lot of work! And a lot of cases to get wrong. Some years ago, I was doing Practice it!, which requests you, in many cases, to write a Java program. The system then compiles and runs your program, and verifies the output. It mostly makes no requirement on how you write it. At some point, I started using System.out.format() for my output statements. If you want to try it: https://practiceit.cs.washington.edu/ Anyway, yes, that is what I thought Java did with them. Though some of my programs use arrays dimensioned [1] instead of the usual wrapper classes.
Back to comp.compilers | Previous | Next — Previous in thread | Find similar
Compilers :) "Tristan B. Velloza Kildaire" <deavmi@redxen.eu> - 2023-01-02 12:28 +0200
Re: Compilers :) Spiros Bousbouras <spibou@gmail.com> - 2023-01-02 20:52 +0000
Re: another C-like language? was Compilers :) Steve Limb <stephenjohnlimb@gmail.com> - 2023-01-03 16:24 +0000
Re: another C-like language? was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-03 12:52 -0800
Re: another C-like language? was Compilers :) arnold@skeeve.com (Aharon Robbins) - 2023-01-04 17:12 +0000
Re: another C-like language? was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-04 12:39 -0800
Re: another C-like language? was Compilers :) "marb...@yahoo.co.uk" <marblypup@yahoo.co.uk> - 2023-01-05 06:27 -0800
Re: another C-like language? was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-05 16:26 -0800
Re: another C-like language? was Compilers :) David Brown <david.brown@hesbynett.no> - 2023-01-06 15:39 +0100
Re: another C-like language? was Compilers :) Kaz Kylheku <864-117-4973@kylheku.com> - 2023-01-09 17:41 +0000
Re: another C-like language? was Compilers :) David Brown <david.brown@hesbynett.no> - 2023-01-10 17:48 +0100
Re: another C-like language? was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-10 15:13 -0800
Re: another C-like language? was Compilers :) David Brown <david.brown@hesbynett.no> - 2023-01-11 13:38 +0100
Re: back in the 60s, another C-like language? was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-11 16:38 -0800
Re: another C-like language? was Compilers :) "marb...@yahoo.co.uk" <marblypup@yahoo.co.uk> - 2023-01-15 04:26 -0800
Re: another C-like language? was Compilers :) Kaz Kylheku <864-117-4973@kylheku.com> - 2023-01-11 11:02 +0000
Re: Scheme is not another C-like language? was Compilers :) George Neuner <gneuner2@comcast.net> - 2023-01-12 02:54 -0500
Re: another C-like language? was Compilers :) Bill Findlay <findlaybill@blueyonder.co.uk> - 2023-01-11 11:58 +0000
Re: another C-like language? was Compilers :) Thomas Koenig <tkoenig@netcologne.de> - 2023-01-11 10:49 +0000
Re: another C-like language? was Compilers :) "marb...@yahoo.co.uk" <marblypup@yahoo.co.uk> - 2023-01-15 04:21 -0800
Re: another C-like language? was Compilers :) Andy Walker <anw@cuboid.co.uk> - 2023-01-15 22:01 +0000
Re: another C-like language? was Compilers :) "Luke A. Guest" <laguest@archeia.com> - 2023-01-13 18:25 +0000
Re: another C-like language? was Compilers :) George Neuner <gneuner2@comcast.net> - 2023-01-13 17:20 -0500
Re: another C-like language? was Compilers :) Kaz Kylheku <864-117-4973@kylheku.com> - 2023-01-14 19:07 +0000
Re: another C-like language? was Compilers :) "marb...@yahoo.co.uk" <marblypup@yahoo.co.uk> - 2023-01-07 02:14 -0800
Re: another C-like language? was Compilers :) David Brown <david.brown@hesbynett.no> - 2023-01-08 20:21 +0100
Re: another C-like language? was Compilers :) Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2023-01-09 04:48 +0100
Re: C scopes, another C-like language? was Compilers :) David Brown <david.brown@hesbynett.no> - 2023-01-09 18:12 +0100
Re: another C-like language? was Compilers :) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-01-09 11:24 -0800
Re: Compilers :) "Tristan B. Velloza Kildaire" <deavmi@redxen.eu> - 2023-01-13 13:41 +0200
Re: Compilers :) Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2023-01-05 01:12 +0100
Re: Compilers :) "Tristan B. Velloza Kildaire" <deavmi@redxen.eu> - 2023-01-13 14:17 +0200
Re: C and Java, was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-13 10:32 -0800
Re: C and Java, was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-13 12:39 -0800
Re: C and Java, was Compilers :) dave_thompson_2@comcast.net - 2023-01-28 10:37 -0500
Re: C and archtecture, C and Java, was Compilers :) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-01-29 19:37 -0800
Re: C and Java, was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-29 21:39 -0800
csiph-web