Solved

simple C question

Posted on 2006-06-26
12
690 Views
Last Modified: 2010-04-15
Hi

I am looking at some legacy c code and i have come across

 list += temp + "\05" + " 0" + "\02";


what is "\05"  ,  "\02"

are these hex constants, binary constants, octal constants ?

thanks

0
Comment
Question by:Vlearns
  • 3
  • 2
  • 2
  • +3
12 Comments
 
LVL 37

Accepted Solution

by:
Harisha M G earned 500 total points
ID: 16988121
Hi, They are octal constants, but no matter what they are, their value remains the same :-)

---
Harish
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16988143
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 16988154
Hi Vlearns,

>> list += temp + "\05" + " 0" + "\02";
This isnt valid C. It might be C++ but not C.

This would be:

 list += temp + '\05' + '0' + '\02';
But even that seems wrong because that would be the same as:

 list += temp + 5 + '0' + 2;

Are you sure you copied it right?

Paul
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 45

Expert Comment

by:Kent Olsen
ID: 16988162
Hi Vlearns,

That isn't legal syntax in modern C.  "\05" is not a character or integer value, it is a string pointer.  The keyword here is pointer.

As legacy code, it MAY have worked on old 8 and/or 16 bit systems, but it certainly isn't ANSI C in today's world.

However, replacing the double quotes with single quotes is a different matter.  (Note the spaced deleted from the " 0" string.)

 list += temp + '\05' + '0' + '\02';

In this case, the \05 and \02 are treated as octal contants so 5 and 2 are added to '0', giving the ASCII character '7'.



Good Luck!
Kent
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 16988181
Snap! :-)
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16988199
Vlearns, yeah I forgot.. as others said, it is valid only in C++ using string class.


0
 
LVL 2

Expert Comment

by:davidnsc1
ID: 16988460
It could be the tragic, pointless addition of string pointers :D
0
 
LVL 22

Expert Comment

by:grg99
ID: 16992373
it depends on whether this is compiled by a C compiler or a C++ compiler.
 list += temp + "\05" + " 0" + "\02";



If it is a C compiler, then the code doesnt make any sense,  as others have noted, adding double quoted strings doesnt do anything useful in C.  You end up with the sum of the addresses of some short strings, which is of no use that I can fathom.

If it's a C++ compiler, then it does make sense if "list" and "temp" are string-type variables.  Although the constants are might peculiar- an escaped zero is just a zero, and doesnt need the escaping.  

Maybe you can give us some more info, like the type of compiler, the name of this file, (.c or .cpp or what), the types of list and temp.

0
 
LVL 7

Expert Comment

by:aib_42
ID: 16999506
Here, let me back up everyone who has said this isn't valid C:

Pointer addition is invalid per §6.3.6 of ANSI 9899.
0
 
LVL 7

Expert Comment

by:aib_42
ID: 16999584
"\05", " 0" and "\02" are all string literals - the first and the last are arrays containing one character each: '\05' and '\02', respectively. (Which are octal character constants representing the ASCII characters ENQ and STX, respectively, as per mgh's reference.) The one in the middle is a two-character array containing the characters ' ' (the space) and '0' (the digit).

Maybe they are all character constants, and the one in the middle is a mistranslated \00?
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C dll call freezes 5 107
valid enum? 6 75
xamarin c# deserialize Json containing nested object 2 121
Loading flat file data in tables 2 39
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question