Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 4, 2009, 01:00 AM   #1
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
??) displays as ]

UILabel.text = @"sin(??)";
gives output: sin(]

UILabel.text = @"??/H";
gives compiler warning about unknown escape string

What is going on? I could probably get around this by doing something like..
NSString *unknownString = @"??"; // I know @"??" displays fine
UILabel.text = [NSString stringWithFormat: @"sin(%@)", unknownString];


BUT I don't want to, I have to work with a lot of ??s in strings, and I need them to not frack up all the time.
I've have tried searching extensively and looking at articals on escaping strings, but cannot figure out the real reason behind this mystery. Probably because Google appears to ignore the ?? in "?? NSString" or "?? escape character"
jared_kipe is offline   0 Reply With Quote
Old Jun 4, 2009, 01:34 AM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Maybe try escaping them?
Code:
UILabel.text = @"sin(\?\?)";
kainjow is offline   0 Reply With Quote
Old Jun 4, 2009, 01:43 AM   #3
jared_kipe
Thread Starter
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Quote:
Originally Posted by kainjow View Post
Maybe try escaping them?
Code:
UILabel.text = @"sin(\?\?)";
This worked, I attempted escaping the first one and it resolved one but not all of my problems.

\??* worked
\?\?* works too
\??) doesn't work
\?\?) does work.

What is damned odd is that if you take out one question mark
?) works
What is the ?? characters actually doing?
jared_kipe is offline   0 Reply With Quote
Old Jun 4, 2009, 01:59 AM   #4
harry65
macrumors member
 
Join Date: Aug 2008
Trigraphs

Check out the following page:

http://en.wikipedia.org/wiki/Digraph_(computing)

Never ran into this before; hmm. Not exactly sure how you turn off the trigraph feature in Xcode. Sounds like it's automatically turned on when you use the -ansi and/or -std=<> gcc flags, which I think Xcode does by default. Good luck with this one...
harry65 is offline   0 Reply With Quote
Old Jun 4, 2009, 02:41 AM   #5
jared_kipe
Thread Starter
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Quote:
Originally Posted by harry65 View Post
Check out the following page:

http://en.wikipedia.org/wiki/Digraph_(computing)

Never ran into this before; hmm. Not exactly sure how you turn off the trigraph feature in Xcode. Sounds like it's automatically turned on when you use the -ansi and/or -std=<> gcc flags, which I think Xcode does by default. Good luck with this one...
Thank you SOOOO much. When I got to the section on Digraphs, I remember reading about those in one of my programming book. That is, the digraphs, I've NEVER seen trigraphs before.

What is still amazing to me is that googling "??) c string" does me no good. Oh and don't bother with the first link, NSFW!
Googling for every combination of ??) and the like turned up nothing either.

EDIT: Programming in Objective-C 2.0 by Stephen Kochan has Digraphs on p505, Trigraphs on p561.

Last edited by jared_kipe; Jun 4, 2009 at 02:52 AM.
jared_kipe is offline   0 Reply With Quote
Old Jun 4, 2009, 03:53 AM   #6
Sander
macrumors 6502
 
Join Date: Apr 2008
This is one of those things which probably should have been gotten rid of long ago, but then that "new" C would break some program written long ago by someone with a weird keyboard without a ] key...

The C standard doesn't prescribe ASCII. There is a definition for the "source character set", where some characters are "optional" and can be replaced by trigraphs. Note that also the $ and @ characters are not in this set, so they are invalid in C identifiers.
Sander is offline   0 Reply With Quote
Old Jun 4, 2009, 12:11 PM   #7
jared_kipe
Thread Starter
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
I should rewrite all my source code replaceing the Obj-C [x] calls with ??(x??)

It is so much more readable don't you think. Oh and the if statements and method curlys

if ( ??(myObject isTrue??) ) ??<
int i=1;
??>

I love it!

I think something like this could probably fix it.
#ifndef ??
#define ?? \?\?
#endif
jared_kipe is offline   0 Reply With Quote
Old Jun 4, 2009, 12:58 PM   #8
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
Quote:
Originally Posted by jared_kipe View Post
I think something like this could probably fix it.
#ifndef ??
#define ?? \?\?
#endif
I was thinking of something like that, too, but from what i read the trigraphs are handled by the preprocessor, so you'd be gaming when the preprocessor performed particular steps, and you may or may not get what you're hoping for.

-Lee
lee1210 is offline   0 Reply With Quote
Old Jun 4, 2009, 02:16 PM   #9
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
I believe there's a checkbox in the build settings to turn trigraphs off.
Catfish_Man is offline   0 Reply With Quote
Old Jun 4, 2009, 06:37 PM   #10
jared_kipe
Thread Starter
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
The more I think about it, the more I think trigraphs/digraphs should be removed from the C spec.

Their ability to confuse and hurt programmers outweighs the need to keep them around.

What is the likeliness that code requiring trigraphs/digraphs is still needing to be compiled?
Any code requiring trigraphs/digraphs could be updated with a simple search and replace trip through an editor OR they can compile it on an older version of GCC or whatever.
jared_kipe is offline   0 Reply With Quote
Old Jun 5, 2009, 06:05 AM   #11
Sander
macrumors 6502
 
Join Date: Apr 2008
Quote:
Originally Posted by jared_kipe View Post
The more I think about it, the more I think trigraphs/digraphs should be removed from the C spec.

Their ability to confuse and hurt programmers outweighs the need to keep them around.
Good, send an email to the C standardization committee. I'm sure they have been hoping that someone would think about it some more, and will be happy to update the specification according to your insights. While you're at it, perhaps you can ask them to remove octal constants too (another fun source of confusion).

Quote:
Any code requiring trigraphs/digraphs could be updated with a simple search and replace trip through an editor OR they can compile it on an older version of GCC or whatever.
That is not the point. C specifies the "source code character set" and that happens to be not the same as ASCII. Remember that C is also used on "obscure" embedded platforms and weird CPUs.

I didn't want to sound harsh. I personally agree that they probably should have been removed, specifically when going to C99, but apparently the standardization committee decided otherwise and they're a bunch of much smarter guys than all of us combined.

Note that GCC ignores trigraphs by default, and only enables them in standards-conforming modes. You can explicitly enable support for them using the -trigraphs compiler switch. You could try adding -no-trigraphs to your project settings. If I try this on the command line, gcc seems to swallow this option...
Sander is offline   0 Reply With Quote
Old Jun 5, 2009, 09:29 AM   #12
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by Sander View Post
That is not the point. C specifies the "source code character set" and that happens to be not the same as ASCII. Remember that C is also used on "obscure" embedded platforms and weird CPUs.
It's not just about weird and obscure platforms. The gcc compiler on your Mac supports source files in Utf-8 format. Try printing strlen (""). Hint: The result is not six.

Basically the rule is: If your source code contains a string with the sequence ??, then replace it with \?\?. Except when the source code really wanted a trigraph character, then replace it with the right character. That way your code will work correctly and without warnings whatever the compiler thinks about trigraphs.
gnasher729 is offline   0 Reply With Quote
Old Jun 5, 2009, 02:28 PM   #13
jared_kipe
Thread Starter
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
This is a PRECOMPILER directive. Does not affect how the machine code will run.

All the substitute characters are in ASCII, they are just for keyboards that didn't have # ] characters when the original source was written.

I do not believe removing this from the C standard would make it harder to develop C software for imbedded or "weird" platforms.
jared_kipe is offline   0 Reply With Quote
Old Jun 5, 2009, 04:52 PM   #14
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by jared_kipe View Post
This is a PRECOMPILER directive. Does not affect how the machine code will run.

All the substitute characters are in ASCII, they are just for keyboards that didn't have # ] characters when the original source was written.

I do not believe removing this from the C standard would make it harder to develop C software for imbedded or "weird" platforms.
Question 1: If this was removed from the C standard, is it possible that some program would not compile anymore?

Question 2: If this was removed from the C standard, is it possible that some program would malfunction?

A change like that is very, very dangerous.
gnasher729 is offline   0 Reply With Quote
Old Jun 5, 2009, 05:11 PM   #15
jared_kipe
Thread Starter
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Quote:
Originally Posted by gnasher729 View Post
Question 1: If this was removed from the C standard, is it possible that some program would not compile anymore?
Yes. Though it would be simple to fix, or they could compile it with an earlier complier.

Quote:
Originally Posted by gnasher729 View Post
Question 2: If this was removed from the C standard, is it possible that some program would malfunction?

A change like that is very, very dangerous.
Not the way I see it. Previously compiled programs would be fine (obviously, they are machine code already). Recompiling code that used them will not compile, thus they wouldn't get malfunctioning machine code, they would get compile errors and no machine code.

OK so maybe not remove it, but make it so it isn't the standard/default way Xcode or other compilers operate.
jared_kipe is offline   0 Reply With Quote
Old Jul 7, 2009, 03:30 AM   #16
Sander
macrumors 6502
 
Join Date: Apr 2008
Sorry to resurrect an old thread, but I recently came across this:
http://www.open-std.org/Jtc1/sc22/wg...2009/n2910.pdf

The deprecation of trigraphs is up for voting, but the authors in this paper argue against it.
Sander is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Retina displays almost pointless? Standard displays downgraded in quality on purpose? Gallion MacBook Pro 33 Aug 23, 2014 08:26 AM
Are 27" Thunderbolt Displays and 27" iMac Displays Comparison Question teleologist Mac Peripherals 2 Mar 27, 2014 08:50 AM
2 displays ok, but 1 not? JAT Mac mini 0 Nov 18, 2012 11:09 AM
Displays rantingrich Mac Peripherals 2 Aug 8, 2012 07:55 PM
New displays? sparkie7 Mac Peripherals 2 Jul 21, 2012 04:14 AM

Forum Jump

All times are GMT -5. The time now is 11:22 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC