![]() |
|
|
#254 | |
|
Basketry That Evening!
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88
3·29·83 Posts |
Quote:
I'm not sure what Perl's solution is, but Java chars are two (8 bit) bytes of UTF-16; Python is capable of using many, many different encodings, and defaults to UTF-8. (For anyone reading this, look in my previous post for another addendum on pointers.) |
|
|
|
|
|
|
#255 | |
|
Bamboozled!
"πΊππ·π·π"
May 2003
Down not across
2A2116 Posts |
Quote:
Finding out which characters I used is left as an exercise. As a hint, the first is from an extant language but the other two are used only to represent now dead scripts. Paul |
|
|
|
|
|
|
#256 | |
|
Basketry That Evening!
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88
3·29·83 Posts |
Quote:
It seems UTF-* are all just different ways of encoding the same ~1.2+ million characters. |
|
|
|
|
|
|
#257 | |||
|
"Jonathan"
Jul 2010
In a tangled web...
5·43 Posts |
Quote:
Quote:
I would love to see an example where sizeof( aaa* ) != sizeof( bbb* ). Quote:
![]() It's only natural IMHO to want to look at one area of your screen to see the type of variable and then look on the other side for the name. Multiple declarations on one line don't really bother me, but look a little messy. something like: int i,j,k; Looks pretty though. (This is all subjective after all). |
|||
|
|
|
|
|
#258 | |
|
Bamboozled!
"πΊππ·π·π"
May 2003
Down not across
3×5×719 Posts |
Quote:
Actually, the second of my example characters is a rather recent addition to the Unicode tables. For many years those who are experts in the language in question could not agree on the members of the definitive set. Other ways of writing the same language are still absent from Unicode AFAIK. One day perhaps I'll compose something in the language in question and post it here. I came extremely close to doing so when trading insults with another poster who delighted in exposing his inadequate knowledge of Latin and Ancient Greek. Unfortunately he earned himself a permanent ban before I collected enough round tuits. |
|
|
|
|
|
|
#259 | |
|
Bamboozled!
"πΊππ·π·π"
May 2003
Down not across
3·5·719 Posts |
Quote:
You'd be amazed at how much difficulty I and a couple of other colleagues had when trying to teach American programmers how to use Unicode in the FlyBase project. They somehow knew that any particular character had a unique representation, that all characters required the same amount of storage in memory and files, and that it is straightforward to check things like the length of strings, that to convert to UPPER CASE or lower case is straightforward, that is easy to determine whether one character sorts before or after another, and so forth. |
|
|
|
|
|
|
#260 | |||
|
Aug 2005
Seattle, WA
176610 Posts |
Quote:
Quote:
Quote:
But assigning the value 0 to a pointer is entirely correct and defined by the language. |
|||
|
|
|
|
|
#261 | ||
|
"Jonathan"
Jul 2010
In a tangled web...
5·43 Posts |
Quote:
Quote:
Yes, I see from Dubslow's link that the "STANDARD" allows for this. I still think this is most confusing though. sizeof(0) is 4 bytes on my machine. Same as the sizeof(int). One could assume that 0 is in fact an integer. So, we are relying on an implicit cast across the "=" to promote this integer to the 8 bytes of a char* (for a 64-bit address). However, with this use of NULL, you could do sizeof(NULL) and get 8 bytes and believe you were just assigning something of pointer type to another thing of pointer type. The wrinkle in my logic is as you pointed out is that according the STANDARD, pointers can be arbitrary sizes and bit patterns and that simple model of how things work is no longer valid. Sorry, but the STANDARD sucks if this is really true. Oh well, enough ranting. And next time I'll read the code twice before commenting. Last fiddled with by jcrombie on 2012-05-20 at 03:11 Reason: Took out the hard returns. |
||
|
|
|
|
|
#262 | |||
|
Aug 2005
Seattle, WA
2×883 Posts |
[Split into two posts because of character-count limitation]
Quote:
Quote:
Quote:
If that book really said that, then no, it is not to believed and I would recommend throwing it out! The "whole point" of void * is exactly the opposite. It's a pointer type which is guaranteed to be assignment compatible with most other pointer types, so it doesn't require a cast when assigning between them. The cast is not necessary; as for whether it's actually harmful, well again, more on that below. |
|||
|
|
|
|
|
#263 | |||
|
Aug 2005
Seattle, WA
6E616 Posts |
Quote:
Quote:
Two (and more importantly) it gets into some fairly deep philosophical questions about language design and exception handling. (When I say exception handling here, I'm not referring specifically to exception handlers as they exist in C++ and Java, though that's related of course; I just mean the handling of exceptional conditions in general.) To take getchar as an example, its interface sounds pretty straightforward: read and return the next character from stdout. What type would you want it to return? Well duh, it's supposed to return a character, so it should return a char. But what happens when something exceptional happens (the most common being there are no more characters in the file)? Well, there are three possibilities that come to mind: 1) f*ck up your nice simple interface by having the return type be something unintuitive, just so it can also indicate an exceptional condition. I.e. do a form of in-band signaling. 2) Add an extra pointer argument so getchar can pass back an error indicator. This, too, f*cks up the nice simple interface. 3) Have a dynamically-scoped exception mechanism, a la C++ and Java, and have getchar throw an exception if something exceptional happens. This preserves the simple interface, but requires a great deal more language support. Obviously the designers of C chose #1, probably because it required the fewest changes and the least thinking. But it also happens to be a choice which is highly prone to mistakes. You would be surprised by the number of professional C programmers who make the same mistake you made, and don't even realized they have a bug, or why. Quote:
Code:
int i; long *p; p = &i; *p = 5; Now it sometimes happens that you really do know better than the compiler what needs to happen, and for such cases C provides an override. That override is the cast operator. You really want to have the above code? Fine, make the first assignment be Code:
p = (long *)&i; I.e. casting is a way of saying to the compiler "I know what I'm doing, let me do this." If you are in the habit of casting things all over the place, just because you can ("Hey, being explicit doesn't hurt"), then you are taking some type safety features of C out of the picture, and thereby preventing the compiler from helping you when it can. |
|||
|
|
|
|
|
#264 | ||
|
Aug 2005
Seattle, WA
2×883 Posts |
Quote:
Quote:
I don't understand your point about sizeof(NULL), or indeed why it matters what sizeof(NULL) is. The compiler just takes care of this for you when it needs to, and you never have to worry about it. And as for the standard sucking, I quite disagree: if it worked the way you apparently want it to, then C would be limited to working on a particular kind of machine architecture (which happens to be about the only architecture still around, but still). The way the standard is written doesn't impose any such requirements on the machine architecture, and that's a good thing. And after all, there's nothing that prevents an implementation from using all-0s as the representation for a null pointer (and that's exactly what pretty much all modern machines/compilers do). |
||
|
|
|