|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
You don't discover if a number is signed or unsigned. You declare it to be one or the other.
Without such a declaration or a convention it is impossible to tell between the two. |
|
|||
|
I need the program which finds whether the values stored in variables is signed or unsigned.
ie. for example int a = 2; unsigned int b = 7; here for 'a' it should print as signed and for 'b' it should print as unsigned. |
|
|||
|
AFAIK there is no way to determine the type of variable at run time. When you compile the code there is no special marker that says 'This is unsigned'.
|
| Sponsored Links |
|
|
|
|||||
|
Like G_Morgan said, it's not possible to find out whether a variable is defined unsigned or signed, but it's possible to find out whether the values stored in the variables are unsigned or signed.
You can use a simple macro, because macros don't care which types it gets. Code:
#define IsSigned(Value) ((Value) < 0) ? (1) : (0) |
|
|||
|
Hi,
Thanks for the quick reply and I got the point. I am trying a program which convert the multiline comment type in a program to single line comment type ie. /*have a nice day */ to //have a //nice day but i am not able to get the end of line in the multiline comment type and so i am not able to put comment symbol in next line for single line comment type. |
|
|||||
|
When you find the start of a multiline-comment (/*) you shall start out by removing it, and then put a singleline-comment (//) instead. Then you check if there's an end of a multiline-comment (*/) on all the following lines. If there's none on a line, you just put a singleline-comment in the start, and so on, until you find it. When you then find it, you put a singleline-comment in, remove the end of multine-comment, and then stop searching.
|
|
|||
|
To change a multi line comment into a series of single line comments I'd use a scanner. This is pretty much a higher level problem than it seems (it's quite easy but needs some understanding of fundamental CS concepts to do it right). It is the very first topic on compiler theory.
Essentially you read a character stream one character at a time simply outputting i until you find a /. If the next character after that is a * you output // and switch state (essentially call a different function). In this new state you simply output every character again with two exceptions: 1. a newline character is followed by //. 2. if you find * and the following character is / then it represents an accepting state and you switch state back to the first state (i.e. return to the first function). You then loop again in that function output all characters until you either meet the condition to enter state 2 again or reach EOF and exit. something like this C Code:
All you need do is implement getChar() and Emit(), initialise the stream and then call state1. Last edited by G_Morgan; 12-03-2007 at 07:57 AM. |
|
|||
|
Hi,
Thanks for the reply... Now i would like to know how the dynamic memory allocated by malloc/calloc/realloc dynamically get deallocated if not released explicitly using free function. thanks in advance.. |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |