I'm following a book on c, and I come to some code that reads a file with 3 lines of text.
#include <stdio.h>
int main (int argc, const char * argv[]) {
...
|
If I define these variables:
double x0, xn, h;
int n;
and I have this mathematical expression:
h = (xn - x0)/n;
Is it necessary that I cast n into double prior doing the division for ... |
What's the precedence in the next expression?
item = (char*)heap + offset;
Is it (char*)(heap + offset) or ((char*)heap) + offset?
|
I'm not able to understand some typecasting syntaxes. For eg.
float f=7.0;
short s=*(short *)&f;
What's happening here short s=*(short *)&f? Looks like we're casting something as a pointer to a short and then ... |
If I do:
int i=3, j=10;
float f;
f=(i+j)/2;
so f won't get value 6.5 but 6.
But,
f=(i+(float)j)/10;//edited
would be f=6.5.
What is the place where this temporary values are stored and why do we need to ... |
why is the output fffffffa rather than 0000000a for this code
char c=0Xaa;
int b=(int)c;
b=b>>4;
printf("%x",b);
what i thought was ... |
Hi, I couldn't figure out how to properly type cast in this case: $ cat -n type_cast.c 1 #include 2 3 typedef unsigned char Byte; 4 typedef signed char Small_Int; 5 6 typedef struct _list 7 { 8 struct _list *np; /* Pointer to next */ 9 struct _list *lp; /* Pointer to last */ 10 Byte type; 11 union ... |
|
Generic Usenet Account I ran a small experiment involving RTTI and dynamic casting. Basically what I did was to cast a base class pointer to a derived type (yes, I know that is not kosher). I then performed dynamic_casting and I invoked RTTI. In both instances, the run time environment did not pick up the fact that what I was claiming ... |
Phil Endecott Dear Experts, I need a function that takes a float, swaps its endianness (htonl) in place, and returns a char* pointer to its first byte. This is one of a family of functions that prepare different data types for passing to another process. I have got confused by the rules about what won't work, what will work, and what ... |
Hi I am interested in opinions on this topic. I have heard that a suffix is not a good solution and type casts are much better for example. ----------------------------------------------------------------- #define MAX_UWORD (T_UWORD)65535 or #define MAX_UWORD 65535u ------------------------------------------------------------------- Where UWORD is unsigned short int. What is your opinion? or why would someone have said using a suffix is no good? For starters ... |
Hello, All! Given the sample piece of code I have: #include #include int main(void) { short int i, j; int k; i = j = 10; k = i + j; return 0; } So, here I expect that 'i' and 'j' will be type-casted to 'int' type, while in debugger (exploring memory dump) I see these variables still ... |
|
|
This question has probably been asked a million time, but here it comes again. I want to learn the difference between the three type cast operators: static_cast, reinterpret_cast, dynamic_cast. A good way to do this is by example. So I will give an example and please tell me what you think: I have a base class A with a virtual destructor, ... |
If char is unsigned, then it would be okay, but I wonder why you want to do this in the first place. If char is signed, then I believe that "the result is implementation-defined or an implementation-defined signal is raised" since those values most likely do not fall in the range of a char. |
|
17. type casting? cboard.cprogramming.comUS currency has a nice property in that if you two items X, Y such that X < Z and Y < Z then X + Y <= Z. What this really means is that if you go from the largest denomination to the smallest and give that denomination as much as possible then you've given that amount in as few ... |
|
|
20. type casting cboard.cprogramming.comEvery value is made up of a bit pattern and a type. The bit pattern doesn't change, but just a bit pattern isn't useful. The type tells C how to represent the bit pattern. An example is that the bit patten 01000001 represented as an int is 65, but represented as a char it's 'A'. The bit pattern doesn't change, but ... |
Code: #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int max; int min; int interval; int numSize; int i; int *num; int *numSquare; printf( "Enter a minimum value: "); scanf( " %d", &min); printf( "Enter a maximum value: "); scanf( " %d", &max); printf( "Enter an interval: "); scanf( " %d", &interval); //numSize = ((max - min) / interval ) + ... |
22. type casting cboard.cprogramming.com |
1: /************************************** 2: * cels2fahr.c: 3: * A program that takes an integer as an argument 4: * and converts it from Celsius (C) to Fahrenheit 5: * (F). 6: ************************************/ 7: 8: #include 9: 10: int main(int argc, char *argv[]) { 11: 12: int fahr = 0; 13: 14: if (argc < 2) { 15: printf("Proper Usage: \n"); 16: ... |
type casting problem? I am attempting to compile some code that I got in an ISO document for barcode generation. When I try to compile it in MS Visual C++, I get the following error: mappings.cpp(147) : error C2440: '=' : cannot convert from 'void *' to 'int *' I have put the line in question in bold and red below. ... |
25. Type casting cboard.cprogramming.comType casting I have a prime number calculator program that uses type casting. The type casting occurs in my "prime_calculator" function, under "Discard remaining composite numbers". If I run it without type casting it, I get an error msg "conversion from double to unsigned long; possible loss of data". I was just wondering where/what is the "double"? mw Code: #include #include ... |
|
I am working on a Windows platform with VS 2005 C++, but the problem relates to c/c++ in general. I have been trying to interface with a GPS software program which uses a message made up to an 20 word array of unsigned shorts; e.g. unsigned short messageData[20]; I have been trying to use data from a home GPS system which ... |
I'm assuming the asterix in the first example is an error on your part, as that line will not compile. Your question doesn't make sense because; 1) You haven't specified a type for n (although, of the standard types supported by C, the only types that can represent it are long long types). 2) Although it is possible with some implementations, ... |
hi ,... I have a question about programming with c#,... suppose we have a textbox that receives a number ,.. and we want to use this number in a mathematical operation ,.. as we know, the type given by a textbox is string ,..and thus, we should convert it to an integer value ... how can we convert it's type to ... |
30. Type Cast forums.devshed.comOk, this might seem like a really simple quesiton to some.. but its not happenging for me rigth now..maybe due to lack of sleep or stress or being a newbie in C..(yeah.. one of those days ) my code seems to be getting more and more complex.. what I'm trying to do is convert a long to a char a char ... |
Mitakeet is correct, although I'd probably say it differently. Typecasting of a void pointer to any other raw pointer type NEVER invokes a constructor. All typecasting does in this case is force the compiler to treat the void pointer as if it is the desired type --- whether the memory pointed to by the void pointer is actually such an object ... |
|
Pointer subtraction takes the size of the type into account. If it's a pointer to char, the size is 1 and with 50 chars the result will be 50. If it's a pointer to int, the size is sizeof(int), and with 50 ints the result will be 50 * sizeof(int). On your system sizeof(int) looks to be 4, and 50 * ... |
|
|
|
/* Low-level i/o sample */typedef struct Hdr { int x, y; } *Phdr;char buff[100];Phdr p;...if (fread(buff,1,100,f) >= sizeof(struct Hdr)){ p = (Phdr)buff; /* as usually, do nothing (char* bits == p bits) * char[] implicitly casted to char* then your cast... * Now the compiler knows that you know ... |
I am having a problem with converting a int to at floating point number. It is my understanding that the converstion should be automatic, but an explicit cast does not help either. This example resultis in Y=0 being displayed. Any explanation would be most appreciated. #include main() { int x; ... |
|