Hi, While developing a state machine compiler I came to a point where I would like the state machine to do a switch() based on current state + event, both being enums. Would it be portable and standards compliant to do something similar to enum states { ...... } current_state; enum events { ...... } received_event; #define INT_BITS (CHAR_BIT * sizeof (int)) #define mix(a,b) (((unsigned long long) (a)) << INT_BITS | (b)) .. .. .. switch (mix(current_state, received_event)) { case mix(foo, bar) : ..... break; } I don't have access to the standards so I can't check my assumptions but I understand that an enum is actually an int and that I need, at minimum, a long long to hold the value of two ints side by side. Is this correct? And, what I really don't know, is if switch () can work on any size integral type or only on int Thanks for any help -- Toni -- comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in square brackets in the subject line. Sorry.

0 |

4/1/2014 6:50:00 AM

Dear all, I had a source code, which was doing matrix integral computation using "int". I had to modify it in order to use "long long". The problem is that "int" was used both for matrix indices and for matrix element. In the version I modified I want to use "long long" for matrix element and "int" for matrix indices. How to be sure that I did not forget anything. "gcc -Wall" accept without difficulties "long long * long" when I would like him to ask for an explicit cast. Could there exist a static source analyzer that de...

I've always had a problem knowing exactly how wide my integer variables were in C, and the little program below has increased my confusion. Run on 3 compilers on the same cpu (32-bit pentium), sometimes int and long int are the same, and long long int is twice the width; or sometimes both long int and long long int are twice the width of int. This apparently all quite normal according to my c99 draft and c-faq.com. However it doesn't alter the fact that this is all very 'woolly' and ambiguous. Integer widths that obey the rule short < int < long int <long long int ...

-------------------------------1109307201 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit >DJGPP already supports 64-bit variables: there's the `long long' data >type which is 64-bit wide. very good ! Thanks. I didn't know that. Probably because it's different in other compilers so when someone sends me a program which uses 64-bit then I can't compile it. #define int long long //#define %i %Li , this doesn't work int i,j; main(){ i=13267364410352; m1:printf("short:%i long:%Li\n",i,i); //this doesn'...

hi! can anyone explain this to me? long long a; what is this "long long"?? something like 8 byte variable (two longs) or what? thanks w3r3w0lf wrote: > hi! > > can anyone explain this to me? > long long a; > > what is this "long long"?? something like 8 byte variable (two longs) or > what? It's usually a sixty-four bit, signed integer type. It's a popular extension. "w3r3w0lf" <asff@asdf.asdf> wrote in message news:c05q2d$j1r$1@ls219.htnet.hr... > can anyone explain this to me? > long long a; > > what is ...

Is there a problem in lcc-win32 with long long and the "<=" operator? I compiled an older program using the integer type long long and got a wrong result: Below a short testprogram to reproduce the error. I would assume to get the result 21 in 0..42 but I get 21 NOT in 0..42. Did I something wrong? O:\Sources\test2>type test2.c #include <stdio.h> int main(void) { long long lTmp = 21; if ( 0 <= lTmp && lTmp <= 42 ) printf("%lld in 0..42\n",lTmp); else printf("%lld NOT in 0..42\n",lTmp); } O:\Sources\...

Hi all, Is long long supposed to be supported in all C99 implementations?If yes is it supposed to be 64 bit at least? GCC says that it supports long long, but i got this: #include <stdio.h> #include <limits.h> int main() { printf("Maximum value for long long: %lld\n", LLONG_MAX); printf("Maximum value for long: %ld\n", LONG_MAX); } C:\c>\mingw\bin\gcc -v Reading specs from /mingw/bin/../lib/gcc-lib/mingw32/3.3.1/specs Configured with: .../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host= mingw32 --target=mingw32 --prefix=/mingw --enable-th...

Hi all, Does long long and unsigned long long types achive worst performance when compiled on x86 platform (Visual C++ Express Edition)? All modern CPUs have 64 bit registers, so I suppose that calculations wouldn't suffer using 64 bit integer values on x86 platforms. I am right? Are long long and unsigned long long part of the standard (C/C++)? Thank you all for help :-P { Fact: They are part of the latest C standard -- ISO/IEC 9899:1999, casually known as "C99". They are NOT part of the current C++ standard -- ISO/IEC 14882:2003, a.k.a. "C++03", though they are...

Quoting the latest draft (n2135), section 26.7 [c.math]: The added signatures are: long abs(long); // labs() long abs(long long); // llabs() Shouldn't abs(long long) have "long long" as return type? -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://ww...

Is there any standard as to what a long and int mean or is it compiler dependent? Or furthermore architecture dependent? I know a short short long int isn't actually a recognised type, but if you wanted to make sure it was 16-bit, 32-bit or 64-bit etc, can you rely on these type names alone? If not, is there any way to ensure you get a 64/32/16-bit int when you want one? Cheers, Dave. David Geering wrote: > Is there any standard as to what a long and int mean or is it compiler > dependent? Or furthermore architecture dependent? It's compiler and architecture dependent. C ...

I need a >49 bit integer type. tried sizeof(long long), says 8. 8 byte = 64 bit right? but when I try to assign a value with more than 32 bit, it fails. To illustrate: for (i=0; i<64; i++){ long long int k = 1<<i; cout<<i<<"\t"<<k<<"\t"<<sizeof(k)<<"\n"; } results in 1 2 8 2 4 8 3 8 8 4 16 8 5 32 8 6 64 8 7 128 8 8 256 8 9 512 8 10 1024 8 11 2048 8 12 4096 8 13 8192 8 14 16384 8 15 32768 8 16 65536 8 17 131072 8 18 262144 8 19 524288 8 20 1048576 8 21 2097152 8 22 4194304 8 23 8388608 8 24 16777216 ...

I recently ran into a problem where a data file downloaded from another site contained more than 4Gb of data and so the index file to items within that data went from unsigned 4 byte integers to unsigned 8 byte integers. Naturally this broke my code which uses fseek(), and can only offset by longs, which on the target OS is a 4 byte integer. There are ways around this using OS calls, but as far as I can tell the C99 standard offers no way to write code that can jump to an arbitrary offset in this type of large data file. Is there any movement in the standards community towards solving this ...

Does the new long long type work from Acorns C++? Any output seems to be truncated to 32 bit values or am i doing something stupid :-) ie unsigned long long int v = 1 << 33; cout << "value:" << v << "\n"; or fprintf(stderr,"value:%x\n", v ); both print out 0 Also, how do i turn off just the "two long declarators" warning. I'm sure i've read it in the docs, but can't seem to find any mention of it. -- mitch@sand-hill.freeserve.co.uk In message <4d7877fb53mitch@sand-hill.freeserve.co.uk>...

How does one covert a interger number in a unsigned long long int (64-bit) to long double (80-bit) storage? I looked at math.h and I found function that convert double to long long, but didn't really see anything that I could use. -- Daniel Rudy Email address has been base64 encoded to reduce spam Decode email address using b64decode or uudecode -m Daniel Rudy wrote: > How does one covert a interger number in a unsigned long long int > (64-bit) to long double (80-bit) storage? my_long_double = my_unsigned_long_long_int; > I looked at math.h and I found function that con...

The essence of a multiply-with-carry RNG is to have declarations in the RNG proc, such as unsigned long mwc( ){ static unsigned long x = 123456789, c = 362436; unsigned long long t, a = 916905990LL; \* then reatedly form the 64-bit t = a*x+c, after which the new carry c is the top 32, and the new x (output), is the bottom 32 bits of t: */ t = a*x+c; c = t>>32; return x=t ; } Some compilers may give a warning for assigning an unsigned long to an unsigned long long. If so, would casting, x=(unsigned long), or chopping, ...