the following program does not compile with g++ 4.1.1:
================================================== ==
// $Id$
// $Source$
#include <stdint.h>
#include <stdio.h>
typedef struct { uint32_t one_c; } chart;
#define as_chart(c) ((chart){one_c:(c)})
#define ascii(x) as_chart((uint8_t)(x))
#define CR 13
#define LF 10
static void wr_ch_unbuffered_dos (void) {
static chart const crlf[2] = { ascii(CR), ascii(LF) };
for (int i = 0; i < 2; i++)
printf("%d\n",crlf[i].one_c);
}
int main (int argc, char *argv[]) {
printf("%d %s\n",argc,argv[0]);
wr_ch_unbuffered_dos();
return 0;
}
================================================== ==
cpp-struct.cc: In function 'void wr_ch_unbuffered_dos()':
cpp-struct.cc:14: warning: missing braces around initializer for 'const chart'
cpp-struct.cc:14: warning: missing braces around initializer for 'const chart'
cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization
cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization
the bad line is
static chart const crlf[2] = { ascii(CR), ascii(LF) };
I am pretty sure code like this worked with g++ 3.
What do I do now?
Thanks!
$ g++ --version
g++ (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1)
--
Sam Steingold ( http://www.podval.org/~sds) on Fedora Core release 5 (Bordeaux) http://palestinefacts.org http://camera.org http://truepeace.org http://israelunderattack.slide.com http://dhimmi.com http://pmw.org.il
The paperless office will become a reality soon after the paperless toilet. 13 2663
Sam Steingold wrote:
the following program does not compile with g++ 4.1.1:
================================================== ==
// $Id$
// $Source$
#include <stdint.h>
#include <stdio.h>
typedef struct { uint32_t one_c; } chart;
#define as_chart(c) ((chart){one_c:(c)})
#define ascii(x) as_chart((uint8_t)(x))
#define CR 13
#define LF 10
static void wr_ch_unbuffered_dos (void) {
static chart const crlf[2] = { ascii(CR), ascii(LF) };
for (int i = 0; i < 2; i++)
printf("%d\n",crlf[i].one_c);
}
int main (int argc, char *argv[]) {
printf("%d %s\n",argc,argv[0]);
wr_ch_unbuffered_dos();
return 0;
}
================================================== ==
cpp-struct.cc: In function 'void wr_ch_unbuffered_dos()':
cpp-struct.cc:14: warning: missing braces around initializer for 'const chart'
cpp-struct.cc:14: warning: missing braces around initializer for 'const chart'
cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization
cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization
the bad line is
static chart const crlf[2] = { ascii(CR), ascii(LF) };
I am pretty sure code like this worked with g++ 3.
What do I do now?
Thanks!
$ g++ --version
g++ (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1)
Looks like you're trying to use C99 features that C++ does not support.
Look for a compiler flag to enable those extensions, or change your
code to valid C++ syntax.
Cheers! --M
* mlimber <zy*****@tznvy.pbz[2006-09-27 07:40:58 -0700]:
>
Sam Steingold wrote:
>the following program does not compile with g++ 4.1.1: ================================================= === // $Id$ // $Source$
#include <stdint.h> #include <stdio.h>
typedef struct { uint32_t one_c; } chart; #define as_chart(c) ((chart){one_c:(c)}) #define ascii(x) as_chart((uint8_t)(x)) #define CR 13 #define LF 10
static void wr_ch_unbuffered_dos (void) { static chart const crlf[2] = { ascii(CR), ascii(LF) }; for (int i = 0; i < 2; i++) printf("%d\n",crlf[i].one_c); }
int main (int argc, char *argv[]) { printf("%d %s\n",argc,argv[0]); wr_ch_unbuffered_dos(); return 0; } ================================================= === cpp-struct.cc: In function 'void wr_ch_unbuffered_dos()': cpp-struct.cc:14: warning: missing braces around initializer for 'const chart' cpp-struct.cc:14: warning: missing braces around initializer for 'const chart' cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization
the bad line is static chart const crlf[2] = { ascii(CR), ascii(LF) };
I am pretty sure code like this worked with g++ 3. What do I do now? Thanks!
$ g++ --version g++ (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1)
Looks like you're trying to use C99 features that C++ does not support.
Look for a compiler flag to enable those extensions, or change your
code to valid C++ syntax.
what would be "valid C++ syntax" in this case?
--
Sam Steingold ( http://www.podval.org/~sds) on Fedora Core release 5 (Bordeaux) http://honestreporting.com http://camera.org http://thereligionofpeace.com http://pmw.org.il http://memri.org http://israelunderattack.slide.com
A poet who reads his verse in public may have other nasty habits.
Sam Steingold wrote:
>* mlimber <zy*****@tznvy.pbz[2006-09-27 07:40:58 -0700]:
Sam Steingold wrote:
>>the following program does not compile with g++ 4.1.1: ================================================ ==== // $Id$ // $Source$
#include <stdint.h> #include <stdio.h>
typedef struct { uint32_t one_c; } chart; #define as_chart(c) ((chart){one_c:(c)}) #define ascii(x) as_chart((uint8_t)(x)) #define CR 13 #define LF 10
static void wr_ch_unbuffered_dos (void) { static chart const crlf[2] = { ascii(CR), ascii(LF) }; for (int i = 0; i < 2; i++) printf("%d\n",crlf[i].one_c); }
int main (int argc, char *argv[]) { printf("%d %s\n",argc,argv[0]); wr_ch_unbuffered_dos(); return 0; } ================================================ ==== cpp-struct.cc: In function 'void wr_ch_unbuffered_dos()': cpp-struct.cc:14: warning: missing braces around initializer for 'const chart' cpp-struct.cc:14: warning: missing braces around initializer for 'const chart' cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization
the bad line is static chart const crlf[2] = { ascii(CR), ascii(LF) };
I am pretty sure code like this worked with g++ 3. What do I do now? Thanks!
$ g++ --version g++ (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1)
Looks like you're trying to use C99 features that C++ does not support. Look for a compiler flag to enable those extensions, or change your code to valid C++ syntax.
what would be "valid C++ syntax" in this case?
Not sure what you're trying to accomplish with it, but on
a 32-bit machine, it's something like
// there is no <stdint.hin C++, but here is the approximation
typedef unsigned uint32_t;
typedef unsigned char uint8_t;
#include <stdio.h>
struct chart { uint32_t one_c; };
#define as_chart(c) (c)
#define ascii(x) as_chart(uint8_t(x))
#define CR 13
#define LF 10
static void wr_ch_unbuffered_dos (void) {
static chart const crlf[2] = { ascii(CR), ascii(LF) };
for (int i = 0; i < 2; i++)
printf("%d\n",crlf[i].one_c);
}
int main (int argc, char *argv[]) {
printf("%d %s\n",argc,argv[0]);
wr_ch_unbuffered_dos();
return 0;
}
Note, however, that 'chart' should probably have a constructor,
but since it changes its nature, adding a c-tor wasn't done.
You need to state your intentions and then we can help you find
a proper C++ solution.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sam Steingold wrote:
* mlimber <zy*****@tznvy.pbz[2006-09-27 07:40:58 -0700]:
Sam Steingold wrote:
the following program does not compile with g++ 4.1.1:
================================================== ==
// $Id$
// $Source$
#include <stdint.h>
#include <stdio.h>
typedef struct { uint32_t one_c; } chart;
#define as_chart(c) ((chart){one_c:(c)})
#define ascii(x) as_chart((uint8_t)(x))
#define CR 13
#define LF 10
static void wr_ch_unbuffered_dos (void) {
static chart const crlf[2] = { ascii(CR), ascii(LF) };
for (int i = 0; i < 2; i++)
printf("%d\n",crlf[i].one_c);
}
int main (int argc, char *argv[]) {
printf("%d %s\n",argc,argv[0]);
wr_ch_unbuffered_dos();
return 0;
}
================================================== ==
cpp-struct.cc: In function 'void wr_ch_unbuffered_dos()':
cpp-struct.cc:14: warning: missing braces around initializer for 'const chart'
cpp-struct.cc:14: warning: missing braces around initializer for 'const chart'
cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization
cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization
the bad line is
static chart const crlf[2] = { ascii(CR), ascii(LF) };
I am pretty sure code like this worked with g++ 3.
What do I do now?
Thanks!
$ g++ --version
g++ (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1)
Looks like you're trying to use C99 features that C++ does not support.
Look for a compiler flag to enable those extensions, or change your
code to valid C++ syntax.
what would be "valid C++ syntax" in this case?
Well, technically stdint.h isn't part of C++, but assuming that
extension exists, you could make your code:
#include <stdint.h>
#include <stdio.h>
typedef struct { uint32_t one_c; } chart;
//#define as_chart(c) ((chart){one_c:(c)}) // Unneeded
//#define ascii(x) as_chart((uint8_t)(x)) // Unneeded
#define CR 13
#define LF 10
static void wr_ch_unbuffered_dos (void) {
static chart const crlf[2] = { {CR}, {LF} }; // Change this
for (int i = 0; i < 2; i++)
printf("%u\n",crlf[i].one_c); // Note format string
}
Of course, if you were going all C++, I'd make some other changes
(viz., convert the typedef to an ordinary struct definition, get rid of
the macros, drop the "static" which has been deprecated in favor of
anonymous namespaces, use iostreams instead of printf [cf. http://www.parashift.com/c++-faq-lit...html#faq-15.1], and
drop the "void" in parentheses).
Cheers! --M
mlimber wrote:
Of course, if you were going all C++, I'd make some other changes
(viz., convert the typedef to an ordinary struct definition, get rid of
the macros, drop the "static" which has been deprecated in favor of
anonymous namespaces, use iostreams instead of printf [cf. http://www.parashift.com/c++-faq-lit...html#faq-15.1], and
drop the "void" in parentheses).
Oh, and add a constructor like Victor said.
Cheers! --M
* Victor Bazarov <i.********@pbzNpnfg.arg[2006-09-27 11:44:39 -0400]:
>
Sam Steingold wrote:
>>* mlimber <zy*****@tznvy.pbz[2006-09-27 07:40:58 -0700]:
Sam Steingold wrote: the following program does not compile with g++ 4.1.1: =============================================== ===== // $Id$ // $Source$
#include <stdint.h> #include <stdio.h>
typedef struct { uint32_t one_c; } chart; #define as_chart(c) ((chart){one_c:(c)}) #define ascii(x) as_chart((uint8_t)(x)) #define CR 13 #define LF 10
static void wr_ch_unbuffered_dos (void) { static chart const crlf[2] = { ascii(CR), ascii(LF) }; for (int i = 0; i < 2; i++) printf("%d\n",crlf[i].one_c); }
int main (int argc, char *argv[]) { printf("%d %s\n",argc,argv[0]); wr_ch_unbuffered_dos(); return 0; } =============================================== ===== cpp-struct.cc: In function 'void wr_ch_unbuffered_dos()': cpp-struct.cc:14: warning: missing braces around initializer for 'const chart' cpp-struct.cc:14: warning: missing braces around initializer for 'const chart' cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization cpp-struct.cc:14: error: cannot convert 'chart' to 'uint32_t' in initialization
the bad line is static chart const crlf[2] = { ascii(CR), ascii(LF) };
I am pretty sure code like this worked with g++ 3. What do I do now? Thanks!
$ g++ --version g++ (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1)
Not sure what you're trying to accomplish with it,
CLISP ( http://clisp.cons.org) is normally compiled with C, but it should
be compilable with C++ to enable some compile-time as well as run-time
checks for debugging. it has always compiled with g++, but I cannot
compile it with g++ 4.1.1 - specifically, I get the errors mentioned above.
note that if I replace
#define as_chart(c) ((chart){one_c:(c)})
with
extern __inline__ chart as_chart (register cint c)
{ register chart ch; ch.one_c = c; return ch; }
it becomes compilable with g++ 4.1
note also that it is only nested initializations that do not work.
chart foo = ascii(60);
works just fine.
so, I should have formulated my question like this: how do I modify
as_chart so that g++ 4.1.1 will accept it?
I am not interested in C++ bells and whistles here (they ARE used
elsewhere, but I do not need them at this place), all I care is how to
make the code compile.
thanks for your kind help/
--
Sam Steingold ( http://www.podval.org/~sds) on Fedora Core release 5 (Bordeaux) http://dhimmi.com http://memri.org http://openvotingconsortium.org http://iris.org.il http://jihadwatch.org http://israelnorthblog.livejournal.com
Money does not "play a role", it writes the scenario.
Sam Steingold wrote:
CLISP (http://clisp.cons.org) is normally compiled with C, but it should
be compilable with C++ to enable some compile-time as well as run-time
checks for debugging. it has always compiled with g++, but I cannot
compile it with g++ 4.1.1 - specifically, I get the errors mentioned above.
note that if I replace
#define as_chart(c) ((chart){one_c:(c)})
This is not valid C++ syntax. If g++ 3.x supported it, it was by
extension.
>
with
extern __inline__ chart as_chart (register cint c)
{ register chart ch; ch.one_c = c; return ch; }
Extern and inline? BTW, __inline__ is non-standard, and using the
register keyword may in fact just confuse the optimizer. Best to leave
that off.
it becomes compilable with g++ 4.1
note also that it is only nested initializations that do not work.
chart foo = ascii(60);
works just fine.
so, I should have formulated my question like this: how do I modify
as_chart so that g++ 4.1.1 will accept it?
Get rid of the one_c:{c} business. That's the problem.
I am not interested in C++ bells and whistles here (they ARE used
elsewhere, but I do not need them at this place), all I care is how to
make the code compile.
See my other post.
Cheers! --M
Sam Steingold wrote:
>* mlimber <zy*****@tznvy.pbz[2006-09-27 09:16:44 -0700]:
>>so, I should have formulated my question like this: how do I modify as_chart so that g++ 4.1.1 will accept it?
Get rid of the one_c:{c} business. That's the problem.
I don't have "one_c:{c}".
I have "((chart){one_c:(c)})".
Seems to me like the same, just with a cast in front of it.
what do I replace it with?
That depends on what it's supposed to do.
Sam Steingold wrote:
>* Rolf Magnus <en******@g-bayvar.qr[2006-09-27 19:24:54 +0200]:
Sam Steingold wrote:
>>>* mlimber <zy*****@tznvy.pbz[2006-09-27 09:16:44 -0700]:
so, I should have formulated my question like this: how do I modify as_chart so that g++ 4.1.1 will accept it? Get rid of the one_c:{c} business. That's the problem. what do I replace it with?
That depends on what it's supposed to do.
convert an integer to a structure:
typedef struct { int one_c; } chart;
#define as_chart(c) ((chart){one_c:(c)})
as_chart should convert an integer to a struct.
How about :
struct chart { chart() {} chart(int c) : one_c(c) {} int one_c; };
inline chart as_chart(int c) { return chart(c); }
* Nate Barney <an********@tznvy.pbz[2006-09-27 13:58:26 -0400]:
>
Sam Steingold wrote:
>>* Rolf Magnus <en******@g-bayvar.qr[2006-09-27 19:24:54 +0200]:
Sam Steingold wrote:
* mlimber <zy*****@tznvy.pbz[2006-09-27 09:16:44 -0700]: > >so, I should have formulated my question like this: how do I modify >as_chart so that g++ 4.1.1 will accept it? Get rid of the one_c:{c} business. That's the problem. what do I replace it with? That depends on what it's supposed to do.
convert an integer to a structure:
typedef struct { int one_c; } chart; #define as_chart(c) ((chart){one_c:(c)})
as_chart should convert an integer to a struct.
How about:
struct chart { chart() {} chart(int c) : one_c(c) {} int one_c; };
inline chart as_chart(int c) { return chart(c); }
this works, thanks!
--
Sam Steingold ( http://www.podval.org/~sds) on Fedora Core release 5 (Bordeaux) http://mideasttruth.com http://palestinefacts.org http://jihadwatch.org http://truepeace.org http://israelnorthblog.livejournal.com http://iris.org.il
You think Oedipus had a problem -- Adam was Eve's mother. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Randy Jackson |
last post by:
Hello everyone.
First of all, apologies in advance if this is a question that gets asked
all the time. I tried to search, but wasn't really sure exactly what to
search for.
Anyway, here's...
|
by: Bo |
last post by:
When I had this code, a and b's value never increases.
for( int i=0, double a=0.0, double b=0.0 ; i<100; a+=0.1, b+=0.2 )
{
printf( "%s\n", i+a+b );
}
This works, however:
double a=0.0,...
|
by: amit |
last post by:
I am trying to compile the sample program genwin.sqc, using nsqlprep
which is used to precompile embedded sql in C. I am getting weird
errors and that is because windows.h is included in the...
|
by: John Smith |
last post by:
Today I experienced something very very weird with STL.
The code snippet below should work, but it doesn't with Microsoft VC++ 6.0.
Ok what I have is a list of network connections. The code below...
|
by: Gernot Frisch |
last post by:
hi,
i don't even know how to desribe the error...
I have a Qt application. Now, there's a .cpp file that I reduced to:
// #include <somefile.h>
int i=45;
/*
long source code
| |
by: Ross |
last post by:
I'm compiling some code over and over with no problems. The only
differences between the versions is slightly different constants that
are specific to various embedded devices that are getting...
|
by: Skybuck Flying |
last post by:
This is the source code for nrand48 from gnuwin32 libgw32c
long int nrand48 (xsubi) unsigned short int xsubi;
{
long int result;
(void) __nrand48_r (xsubi, &__libc_drand48_data, &result);
...
|
by: Josué Andrade Gomes |
last post by:
Take this code:
1: int main()
2: {
3: unsigned short x = { 1, 2, 3, 4, 5 };
4: unsigned short sum = 0;
5:
6: for (int i = 0; i < 5; ++i) {
7: sum += x;
8: }
9: }
|
by: Joe Van Dyk |
last post by:
I'm compiling some code on a IRIX compiler (MIPSpro Compilers: Version
7.4.2m) with all warnings turned on, and I'm getting some of these warnings:
cc-3649 CC: ERROR at end of source
all...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |