473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Introduce a C Compiler ucc

ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.
Jun 27 '08 #1
61 3174
On May 11, 4:15 am, dreamAnders <dream_and...@yahoo.com.cnwrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.
Your implementation of assert in ucc/ucl/linux/include/assert.h is not
ANSI C, (or ISO C) as it evaluates it's parameter more than once if
NDEBUG is not defined.
Example: assert(printf("hello world\n")); would call print twice.

I suggest you rewrite _assert (and also rename to _Assert) to return
void, and make the check twice there.
Jun 27 '08 #2
On May 10, 9:15 pm, dreamAnders <dream_and...@yahoo.com.cnwrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.
At about 1 comment per 1000 lines of code it may be difficult to get
this adopted for "research and instructional use".

--
Robert Gamble
Jun 27 '08 #3
On May 11, 9:35 am, vipps...@gmail.com wrote:
On May 11, 4:15 am, dreamAnders <dream_and...@yahoo.com.cnwrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.

Your implementation of assert in ucc/ucl/linux/include/assert.h is not
ANSI C, (or ISO C) as it evaluates it's parameter more than once if
NDEBUG is not defined.
Example: assert(printf("hello world\n")); would call print twice.

I suggest you rewrite _assert (and also rename to _Assert) to return
void, and make the check twice there.
No, It will not evaluate its parameter more than once.

#define assert(e) ((void)((e)||_assert(#e, __FILE__, __LINE__)))

please notice that the second e's appearance, it is '#e'
Jun 27 '08 #4
yes, I accept this . Nearly no comments. I wanted to write this code
in a self-explanatory way. And I provide an internal implementation
document, hope that will help developers understanding the code.

On May 11, 9:42 am, Robert Gamble <rgambl...@gmail.comwrote:
On May 10, 9:15 pm, dreamAnders <dream_and...@yahoo.com.cnwrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.

At about 1 comment per 1000 lines of code it may be difficult to get
this adopted for "research and instructional use".

--
Robert Gamble

Jun 27 '08 #5
Dan

"dreamAnders" <dr**********@yahoo.com.cnwrote in message
news:1b**********************************@p25g2000 pri.googlegroups.com...
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.
Can it compile itself?
Jun 27 '08 #6
On May 10, 11:20*pm, "Dan" <vo...@sometwher.worldwrote:
"dreamAnders" <dream_and...@yahoo.com.cnwrote in message

news:1b**********************************@p25g2000 pri.googlegroups.com...
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.

Can it compile itself?
From User's Manual:

(3) run make test, this will test if ucc can compile itself and run
successfully.
The command performs the following operations:
1) use ucc to build ucl, the output is named as ucl1
2) backup ucl under /usr/local/lib/ucc, copy ucl1 to this
directory and rename it to ucl
3) use ucc to build ucl again, the output is named as ucl2
4) run cmp /b ucl1 ucl2, these two files should be identical
Jun 27 '08 #7
On Sat, 10 May 2008 18:15:57 -0700, dreamAnders wrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines. The
lexer, parser and code generator are all hand-written. The code
structure is very clear and straightforward. And there is an interesting
value numbering algorithm. It also has a document explaining the
internal implementation. If you are interested at this compiler, you can
download it from http://sourceforge.net/projects/ucc, which will help
you to master the C language.
Do you have a site dedicated to your project?
Rui Maciel
Jun 27 '08 #8
On May 11, 2:15*am, dreamAnders <dream_and...@yahoo.com.cnwrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.
As I understand it, this is just a bare compiler source code?

There are no binaries, so another compiler is needed to get started.

There appear to be no standard header files or library files,
presumably you are relying on these things from another compiler?
--
Bartc
Jun 27 '08 #9
On May 10, 9:15*pm, dreamAnders <dream_and...@yahoo.com.cnwrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.
Congratulations. I hope this project will evolve quickly.
Jun 27 '08 #10
On May 11, 11:36*am, "noagbodjivic...@gmail.com"
<noagbodjivic...@gmail.comwrote:
On May 10, 9:15*pm, dreamAnders <dream_and...@yahoo.com.cnwrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.

Congratulations. I hope this project will evolve quickly.
Also, I don't really like the fact that one must have Ms Studio to
compile the compiler :) Can't you distribute binaries?
Jun 27 '08 #11
dreamAnders wrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.
Your files all have DOS line endings, not good for a cross platform project.

--
Ian Collins.
Jun 27 '08 #12
Ian Collins wrote:
dreamAnders wrote:
>ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.

Your files all have DOS line endings, not good for a cross platform project.
I see you also used unnamed unions in structs, which isn't standard.

You really should use standard C for a standard C compiler!

--
Ian Collins.
Jun 27 '08 #13
In article <68*************@mid.individual.net>,
Ian Collins <ia******@hotmail.comwrote:
>You really should use standard C for a standard C compiler!
Why? Would it be wrong to write a C compiler in, say, Lisp? The
considerations for what language or dialect to use for a C compiler
are no stricter than for any other project. In fact, they're less
strict, since so long as you support the extensions you use you can be
sure that there's a compiler that will compile it for the platforms
you support.

-- Richard
--
:wq
Jun 27 '08 #14
Richard Tobin wrote:
In article <68*************@mid.individual.net>,
Ian Collins <ia******@hotmail.comwrote:
>You really should use standard C for a standard C compiler!

Why? Would it be wrong to write a C compiler in, say, Lisp? The
considerations for what language or dialect to use for a C compiler
are no stricter than for any other project. In fact, they're less
strict, since so long as you support the extensions you use you can be
sure that there's a compiler that will compile it for the platforms
you support.
Why? Because one of the claims for the source was it "will help you to
master the C language."

Maybe that should read "will help you to master the gcc language." :)

--
Ian Collins.
Jun 27 '08 #15
On Sun, 11 May 2008 22:50:56 +0000, Richard Tobin wrote:
Why? Would it be wrong to write a C compiler in, say, Lisp?
I believe that you've entirely missed the point. What was pointed out was
that the use of a non-standard extensions, which not only goes against
the objective that you set yourself to accomplish but also needlessly
screws things up for those who want to build it with any compiler that
doesn't support those non-standard extensions.
Rui Maciel
Jun 27 '08 #16
In article <68*************@mid.individual.net>,
Ian Collins <ia******@hotmail.comwrote:
>Why? Because one of the claims for the source was it "will help you to
master the C language."
Fair enough, but you said something far more general:
>>You really should use standard C for a standard C compiler!
-- Richard
--
:wq
Jun 27 '08 #17
On May 11, 11:41*pm, "noagbodjivic...@gmail.com"
<noagbodjivic...@gmail.comwrote:
On May 11, 11:36*am, "noagbodjivic...@gmail.com"

<noagbodjivic...@gmail.comwrote:
On May 10, 9:15*pm, dreamAnders <dream_and...@yahoo.com.cnwrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.
Congratulations. I hope this project will evolve quickly.

Also, I don't really like the fact that one must have Ms Studio to
compile the compiler :) Can't you distribute binaries?
Thanks. I am afraid that ucc is a stand-alone compiler. On Windows, It
rely on VC'header
files, library files, the preprocessor,assembler and linker. On Linux,
It rely on gcc
for that. So If I distribute binaries, users will find it cannot work.

I hope the project will evolve quickly. I need more help.
Jun 27 '08 #18
On May 12, 4:13*am, Ian Collins <ian-n...@hotmail.comwrote:
dreamAnders wrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.

Your files all have DOS line endings, not good for a cross platform project.

--
Ian Collins.
Thank you for your suggestion.

And yes, ucc supports anonymous union. Personally, I like anonymous
union so much,
and most compilers support it. So I want to support it too.
Jun 27 '08 #19
On May 11, 11:41*pm, "noagbodjivic...@gmail.com"
<noagbodjivic...@gmail.comwrote:
On May 11, 11:36*am, "noagbodjivic...@gmail.com"

<noagbodjivic...@gmail.comwrote:
On May 10, 9:15*pm, dreamAnders <dream_and...@yahoo.com.cnwrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.
Congratulations. I hope this project will evolve quickly.

Also, I don't really like the fact that one must have Ms Studio to
compile the compiler :) Can't you distribute binaries?
Thanks. I am afraid that ucc is not a stand-alone compiler. On
Windows, It
rely on VC'header files, library files, the preprocessor,assembler and
linker. On Linux, It rely on gcc for that. So If I distribute
binaries, users will find it cannot work.

I hope the project will evolve quickly. I need more help.
Jun 27 '08 #20
On May 12, 4:13*am, Ian Collins <ian-n...@hotmail.comwrote:
dreamAnders wrote:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.

Your files all have DOS line endings, not good for a cross platform project.

--
Ian Collins.
Thank you for your suggestion.

Personally, I like unnamned union in structs so much and most
compilers support it. So I want to support it too.
Jun 27 '08 #21
On May 12, 11:21*am, dreamAnders <dream_and...@yahoo.com.cnwrote:
On May 12, 4:13*am, Ian Collins <ian-n...@hotmail.comwrote:
Your files all have DOS line endings, not good for a cross platform project.
So what line ending should be used for a cross-pltform project?

What /is/ a DOS line ending anyway?
Personally, I like unnamned union in structs so much and most
compilers support it. So I want to support it too.
Well said.

There's a whole bunch of these minor but extremely useful little
extensions, that really should be available on every compiler. And
they should be available now, no excuses.

--
Bartc
Jun 27 '08 #22
In article <72**********************************@25g2000hsx.g ooglegroups.com>,
Bart <bc@freeuk.comwrote:
>On May 12, 11:21*am, dreamAnders <dream_and...@yahoo.com.cnwrote:
>On May 12, 4:13*am, Ian Collins <ian-n...@hotmail.comwrote:
Your files all have DOS line endings, not good for a cross platform
project.

So what line ending should be used for a cross-pltform project?

What /is/ a DOS line ending anyway?
>Personally, I like unnamned union in structs so much and most
compilers support it. So I want to support it too.

Well said.

There's a whole bunch of these minor but extremely useful little
extensions, that really should be available on every compiler. And
they should be available now, no excuses.
Uh Oh.

(You're going to get it now...)

Jun 27 '08 #23
Bart wrote:
On May 12, 11:21*am, dreamAnders <dream_and...@yahoo.com.cnwrote:
>On May 12, 4:13*am, Ian Collins <ian-n...@hotmail.comwrote:
Your files all have DOS line endings, not good for a cross platform
project.

So what line ending should be used for a cross-pltform project?

What /is/ a DOS line ending anyway?
It's the ASCII sequence CR-LF, i.e., the ASCII character code 13
followed by the ASCII character code 10. It's the standard line
separator under CP/M, DOS and Windows; maybe other system too.

The Unix world just uses a LF and MacOS uses just a CR. There are
utilities availbale to convert a file between these formats. It's also
trivial to write a standard C program to do the job.

Jun 27 '08 #24
On May 12, 7:56*am, Bart <b...@freeuk.comwrote:
On May 12, 11:21*am, dreamAnders <dream_and...@yahoo.com.cnwrote:
On May 12, 4:13*am, Ian Collins <ian-n...@hotmail.comwrote:
Your files all have DOS line endings, not good for a cross platform project.

So what line ending should be used for a cross-pltform project?

What /is/ a DOS line ending anyway?
Personally, I like unnamned union in structs so much and most
compilers support it. So I want to support it too.

Well said.

There's a whole bunch of these minor but extremely useful little
extensions, that really should be available on every compiler. And
they should be available now, no excuses.

--
Bartc
Windows/Dos : \n\r
Unix/Linux : \n
Mac OS X : \r

OS makers want us to believe this... and we are believers.
Jun 27 '08 #25
In article <1b**********************************@p25g2000pri. googlegroups.com>,
dreamAnders <dr**********@yahoo.com.cnwrote:
>ucc is an ANSI C Compiler.
I tried compiling some code of mine, and ran into a few problems:

The -D option doesn't seem to have any effect - the macro is
not defined.

Typedefs like "typedef void fv(int);" don't seem to work; when it
later encounters "fv *foo" it reports "Typedef name cannot be used as
variable". "typedef void (*fv)(int);" is ok.

It rejects conditional operators where one result is a pointer and the
other is 0. For example, "int *i, j=2; i = j 1 ? &j : 0;".
It should treat the 0 as a null pointer of the type of the other result.

-- Richard
--
:wq
Jun 27 '08 #26
In article <g0**********@registered.motzarella.org>,
santosh <sa*********@gmail.comwrote:
>The Unix world just uses a LF and MacOS uses just a CR.
Old MacOS used CR. MacOS X is unix and uses LF as you would expect.

-- Richard
--
:wq
Jun 27 '08 #27
no*************@gmail.com wrote:
On May 12, 7:56*am, Bart <b...@freeuk.comwrote:
>On May 12, 11:21*am, dreamAnders <dream_and...@yahoo.com.cnwrote:
On May 12, 4:13*am, Ian Collins <ian-n...@hotmail.comwrote:
Your files all have DOS line endings, not good for a cross
platform project.

So what line ending should be used for a cross-pltform project?

What /is/ a DOS line ending anyway?
Personally, I like unnamned union in structs so much and most
compilers support it. So I want to support it too.

Well said.

There's a whole bunch of these minor but extremely useful little
extensions, that really should be available on every compiler. And
they should be available now, no excuses.

--
Bartc

Windows/Dos : \n\r
Unix/Linux : \n
Mac OS X : \r

OS makers want us to believe this... and we are believers.
The C escape sequence '\n' is translated by the C compiler and the
runtime library into whatever sequence the target platform uses for
separating lines. Thus on Windows a '\n' in an output operation is
translated into a CRLF sequence, while under Unix it is replaced by a
LF character, and so on.

So the platform specific end-of-line sequences are independent of the C
escape sequences.

Jun 27 '08 #28
On May 12, 10:12*pm, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
In article <1b33b933-749a-48ca-af4f-d7f87f8eb...@p25g2000pri.googlegroups.com>,

dreamAnders *<dream_and...@yahoo.com.cnwrote:
ucc is an ANSI C Compiler.

I tried compiling some code of mine, and ran into a few problems:

The -D option doesn't seem to have any effect - the macro is
not defined.

Typedefs like "typedef void fv(int);" don't seem to work; when it
later encounters "fv *foo" it reports "Typedef name cannot be used as
variable". * "typedef void (*fv)(int);" is ok.

It rejects conditional operators where one result is a pointer and the
other is 0. *For example, "int *i, j=2; i = j 1 ? &j : 0;".
It should treat the 0 as a null pointer of the type of the other result.

-- Richard
--
:wq
Thank you very much for tesing the compiler. I have corrected the bugs.
Jun 27 '08 #29
dreamAnders <dr**********@yahoo.com.cnwrites:
On May 12, 10:12*pm, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
>In article <1b33b933-749a-48ca-af4f-d7f87f8eb...@p25g2000pri.googlegroups.com>,

dreamAnders *<dream_and...@yahoo.com.cnwrote:
>ucc is an ANSI C Compiler.

I tried compiling some code of mine, and ran into a few problems:
[snip]
>
Thank you very much for tesing the compiler. I have corrected the bugs.
Thank you for providing an excellent example of how to respond to
bug reports. I hope that any other compiler implementers who hang
out here will take it to heart.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Jun 27 '08 #30
In article <ea**********************************@y18g2000pre. googlegroups.com>,
dreamAnders <dr**********@yahoo.com.cnwrote:
>Thank you very much for tesing the compiler. I have corrected the bugs.
That was quick!

But I still find the conditional operator doesn't work when the
second operand is 0 and the third is a pointer. (It now works
with them the other way round.)

I also have a problem with files that include sys/socket.h (this
is on Linux). I don't know if it's a problem with your compiler as
such or with the compatibility of the header files. I get this
error:

(/usr/include/bits/socket.h,165):error:Expect type specifier or qualifier
(/usr/include/bits/socket.h,165):error:Expect ;
(/usr/include/bits/socket.h,165):error:Expect type specifier or qualifier
(/usr/include/bits/socket.h,166):error:Undeclared identifier: __uint64_t

-- Richard
--
:wq
Jun 27 '08 #31
Richard Tobin wrote:
In article <ea**********************************@y18g2000pre. googlegroups.com>,
dreamAnders <dr**********@yahoo.com.cnwrote:
>Thank you very much for tesing the compiler. I have corrected the bugs.

That was quick!

But I still find the conditional operator doesn't work when the
second operand is 0 and the third is a pointer. (It now works
with them the other way round.)

I also have a problem with files that include sys/socket.h (this
is on Linux). I don't know if it's a problem with your compiler as
such or with the compatibility of the header files. I get this
error:

(/usr/include/bits/socket.h,165):error:Expect type specifier or qualifier
(/usr/include/bits/socket.h,165):error:Expect ;
(/usr/include/bits/socket.h,165):error:Expect type specifier or qualifier
(/usr/include/bits/socket.h,166):error:Undeclared identifier: __uint64_t

-- Richard
Most include files under linux are unusable by anything else but gcc

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jun 27 '08 #32
Another problem: the program below reports

(test.c,10):error:struct or union member key doesn't exsist
(test.c,10):warning:conversion between pointer and integer without a cast

The error goes away if the "const" in the declaration of hp is
removed.

typedef struct hash_entry {
void *key;
} HashEntryStruct;

HashEntryStruct h;

int main(void)
{
const HashEntryStruct *hp = &h;
void *key = hp->key;

return 0;
}

-- Richard
--
:wq
Jun 27 '08 #33
In article <48*********************@news.orange.fr>,
jacob navia <ja***@nospam.orgwrote:
>Most include files under linux are unusable by anything else but gcc
Yes, but the ucc documentation says it uses gcc's headers.

I suspect the problem is something about 64-bit types.

-- Richard
--
:wq
Jun 27 '08 #34
dreamAnders wrote, On 12/05/08 11:10:

<snip>
And yes, ucc supports anonymous union. Personally, I like anonymous
union so much,
and most compilers support it. So I want to support it too.
There is nothing wrong with supporting extensions. However, you should
also provide a mode which conforms to the standard including issuing all
required diagnostics (a diagnostic could be, WARNING: Extension fred used").

Also you should understand that by using extensions where they are not
required you are limiting the portability of your code more than
necessary and also preventing your compiler from being compiled with the
maximum warning levels supported by compilers. Try using gcc options
"-ansi -pedantic -Wall -Wextra" and see what it says. MS Visual Studio
also can be configured to give a lot of useful warnings.
--
Flash Gordon
Jun 27 '08 #35
Flash Gordon wrote:
dreamAnders wrote, On 12/05/08 11:10:

<snip>
>And yes, ucc supports anonymous union. Personally, I like anonymous
union so much,
and most compilers support it. So I want to support it too.

There is nothing wrong with supporting extensions. However, you should
also provide a mode which conforms to the standard including issuing
all required diagnostics (a diagnostic could be, WARNING: Extension
fred used").

Also you should understand that by using extensions where they are not
required you are limiting the portability of your code more than
necessary and also preventing your compiler from being compiled with
the maximum warning levels supported by compilers. Try using gcc
options "-ansi -pedantic -Wall -Wextra" and see what it says. MS
Visual Studio also can be configured to give a lot of useful warnings.
I have found that the Intel C compiler generally tends to print more
diagnostics than either gcc or MSVC. With the -Wall option it's
almost "lint-like" in it's diagnostic verbosity.

Jun 27 '08 #36
On 12 May, 18:16, Flash Gordon <s...@flash-gordon.me.ukwrote:
dreamAnders wrote, On 12/05/08 11:10:

<snip>
And yes, ucc supports anonymous union. Personally, I like anonymous
union so much,
and most compilers support it. So I want to support it too.

There is nothing wrong with supporting extensions. However, you should
also provide a mode which conforms to the standard including issuing all
required diagnostics (a diagnostic could be, WARNING: Extension fred used").
It occurs to me that the opening poster did not say to
which standard he tries to conform. Unless "ANSI C"
has only one interpretation.
Jun 27 '08 #37
On 12 May, 15:12, santosh <santosh....@gmail.comwrote:
noagbodjivic...@gmail.com wrote:
On May 12, 7:56 am, Bart <b...@freeuk.comwrote:
On May 12, 11:21 am, dreamAnders <dream_and...@yahoo.com.cnwrote:
On May 12, 4:13 am, Ian Collins <ian-n...@hotmail.comwrote:
Your files all have DOS line endings, not good for a cross
platform project.
So what line ending should be used for a cross-pltform project?
What /is/ a DOS line ending anyway?
Personally, I like unnamned union in structs so much and most
compilers support it. So I want to support it too.
Well said.
There's a whole bunch of these minor but extremely useful little
extensions, that really should be available on every compiler. And
they should be available now, no excuses.
--
Bartc
Windows/Dos : \n\r
Unix/Linux : \n
Mac OS X : \r
OS makers want us to believe this... and we are believers.

The C escape sequence '\n' is translated by the C compiler and the
runtime library into whatever sequence the target platform uses for
separating lines. Thus on Windows a '\n' in an output operation is
translated into a CRLF sequence, while under Unix it is replaced by a
LF character, and so on.
Of course all that applies if the file was opened in
text mode.

Jun 27 '08 #38
Spiros Bousbouras wrote:
On 12 May, 15:12, santosh <santosh....@gmail.comwrote:
>The C escape sequence '\n' is translated by the C compiler and the
runtime library into whatever sequence the target platform uses for
separating lines. Thus on Windows a '\n' in an output operation is
translated into a CRLF sequence, while under Unix it is replaced by a
LF character, and so on.

Of course all that applies if the file was opened in
text mode.
Not on a Unix systems, where there isn't a "text mode".

--
Ian Collins.
Jun 27 '08 #39
dreamAnders wrote:
On May 12, 4:13 am, Ian Collins <ian-n...@hotmail.comwrote:
>dreamAnders wrote:
>>ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.
Your files all have DOS line endings, not good for a cross platform project.

Thank you for your suggestion.

And yes, ucc supports anonymous union. Personally, I like anonymous
union so much,
and most compilers support it. So I want to support it too.
My point was one of the claims for the source was it "will help you to
master the C language.". Anonymous unions aren't part of the C
language, they are an extension offered by some compilers.

--
Ian Collins.
Jun 27 '08 #40
Ian Collins <ia******@hotmail.comwrites:
Spiros Bousbouras wrote:
>On 12 May, 15:12, santosh <santosh....@gmail.comwrote:
>>The C escape sequence '\n' is translated by the C compiler and the
runtime library into whatever sequence the target platform uses for
separating lines. Thus on Windows a '\n' in an output operation is
translated into a CRLF sequence, while under Unix it is replaced by a
LF character, and so on.

Of course all that applies if the file was opened in
text mode.
Not on a Unix systems, where there isn't a "text mode".
Yes, it does apply. On an output operation, '\n' is replaced by an
ASCII LF character. (As it happens, '\n' already is an ASCII LF
character, so the replacement is particularly easy to do.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #41
On 12 May, 21:09, Ian Collins <ian-n...@hotmail.comwrote:
Spiros Bousbouras wrote:
On 12 May, 15:12, santosh <santosh....@gmail.comwrote:
The C escape sequence '\n' is translated by the C compiler and the
runtime library into whatever sequence the target platform uses for
separating lines. Thus on Windows a '\n' in an output operation is
translated into a CRLF sequence, while under Unix it is replaced by a
LF character, and so on.
Of course all that applies if the file was opened in
text mode.

Not on a Unix systems, where there isn't a "text mode".
Yes there is , it's just no different from binary mode.

Jun 27 '08 #42
Spiros Bousbouras wrote, On 12/05/08 20:45:
On 12 May, 18:16, Flash Gordon <s...@flash-gordon.me.ukwrote:
>dreamAnders wrote, On 12/05/08 11:10:

<snip>
>>And yes, ucc supports anonymous union. Personally, I like anonymous
union so much,
and most compilers support it. So I want to support it too.
There is nothing wrong with supporting extensions. However, you should
also provide a mode which conforms to the standard including issuing all
required diagnostics (a diagnostic could be, WARNING: Extension fred used").

It occurs to me that the opening poster did not say to
which standard he tries to conform. Unless "ANSI C"
has only one interpretation.
ANSI C has three main interpretations that I can think of. C89, C95 and
C99. It is most often used to mean C89 because ANSI standardised C first
in 1989, but they adopted the amendment that made it what is often known
as C95 and the 1999 standard, so ANSI C can certainly refer to them as
well. I find it hard to see how someone can use the term "ANSI C" to
refer to something other than the language as it has been standardised.

In any case, I would consider my comment valid whether the OP had
mentioned ANSI C, ISO C or just C.
--
Flash Gordon
Jun 27 '08 #43
Keith Thompson wrote:
Ian Collins <ia******@hotmail.comwrites:
>Spiros Bousbouras wrote:
>>On 12 May, 15:12, santosh <santosh....@gmail.comwrote:
The C escape sequence '\n' is translated by the C compiler and the
runtime library into whatever sequence the target platform uses for
separating lines. Thus on Windows a '\n' in an output operation is
translated into a CRLF sequence, while under Unix it is replaced by a
LF character, and so on.
Of course all that applies if the file was opened in
text mode.
Not on a Unix systems, where there isn't a "text mode".

Yes, it does apply. On an output operation, '\n' is replaced by an
ASCII LF character. (As it happens, '\n' already is an ASCII LF
character, so the replacement is particularly easy to do.)
'a' is also replaced by ASCII 'a' character, so what's the difference?

--
Ian Collins.
Jun 27 '08 #44
On 12 May, 21:24, Flash Gordon <s...@flash-gordon.me.ukwrote:
Spiros Bousbouras wrote, On 12/05/08 20:45:
On 12 May, 18:16, Flash Gordon <s...@flash-gordon.me.ukwrote:
dreamAnders wrote, On 12/05/08 11:10:
<snip>
>And yes, ucc supports anonymous union. Personally, I like anonymous
union so much,
and most compilers support it. So I want to support it too.
There is nothing wrong with supporting extensions. However, you should
also provide a mode which conforms to the standard including issuing all
required diagnostics (a diagnostic could be, WARNING: Extension fred used").
It occurs to me that the opening poster did not say to
which standard he tries to conform. Unless "ANSI C"
has only one interpretation.

ANSI C has three main interpretations that I can think of. C89, C95 and
C99. It is most often used to mean C89 because ANSI standardised C first
in 1989, but they adopted the amendment that made it what is often known
as C95 and the 1999 standard, so ANSI C can certainly refer to them as
well. I find it hard to see how someone can use the term "ANSI C" to
refer to something other than the language as it has been standardised.

In any case, I would consider my comment valid whether the OP had
mentioned ANSI C, ISO C or just C.
I wasn't suggesting that your comment isn't valid
I was just curious which standard the OP is aiming
for.
Jun 27 '08 #45
In article <68*************@mid.individual.net>,
Ian Collins <ia******@hotmail.comwrote:
>Keith Thompson wrote:
>Ian Collins <ia******@hotmail.comwrites:
>>Not on a Unix systems, where there isn't a "text mode".

Yes, it does apply. On an output operation, '\n' is replaced by an
ASCII LF character. (As it happens, '\n' already is an ASCII LF
character, so the replacement is particularly easy to do.)
'a' is also replaced by ASCII 'a' character, so what's the difference?
On ASCII systems, 'a' IS an ASCII 'a' character, in all contexts a C
program cares about.
In the context of I/O operations on a file opened in text mode, '\n' is
a C end-of-line character, which is converted to a host-OS end-of-line
on output. The fact that '\n' is an ASCII LF on ASCII systems and that
a Unix end-of-line is an ASCII LF at the end of the line makes the
conversion in this case trivial, but it IS a conversion.
(If that bothers you, consider: I have a char *, and I assign it to a
void *. Did a conversion happen? Did anything change as a result?[1])

In other words: On Unix, text mode is indistinguishable from binary
mode, but they are still two distinct modes.
dave

[1] Answers: Yes, a conversion happened; and yes, the type of the
pointer changed, but (unless you're on a DS9K.x where they've found
a loophole in the "same representation" requirement), nothing about
the actual bits making up the pointer has changed.

--
Dave Vandervies dj3vande at eskimo dot com
>I am trying to move 3 bits from left to right with >operator
Try holding the 3 bits in place, but shift the rest of your computer's memory
right to left. --Kaz Kylheku gives stupid answers to stupid questions in CLC
Jun 27 '08 #46
Ian Collins <ia******@hotmail.comwrites:
Keith Thompson wrote:
>Ian Collins <ia******@hotmail.comwrites:
>>Spiros Bousbouras wrote:
On 12 May, 15:12, santosh <santosh....@gmail.comwrote:
The C escape sequence '\n' is translated by the C compiler and the
runtime library into whatever sequence the target platform uses for
separating lines. Thus on Windows a '\n' in an output operation is
translated into a CRLF sequence, while under Unix it is replaced by a
LF character, and so on.
Of course all that applies if the file was opened in
text mode.

Not on a Unix systems, where there isn't a "text mode".

Yes, it does apply. On an output operation, '\n' is replaced by an
ASCII LF character. (As it happens, '\n' already is an ASCII LF
character, so the replacement is particularly easy to do.)
'a' is also replaced by ASCII 'a' character, so what's the difference?
I don't recall claiming that there is one, but now that you mention it
.... actually, there isn't much of a difference. C99 7.19.2p2:

Characters may have to be added, altered, or deleted on input and
output to conform to differing conventions for representing text
in the host environment. Thus, there need not be a one-to-one
correspondence between the characters in a stream and those in the
external representation.

which covers both '\n' conversion and any conversion that might be
necessary for 'a' and other "ordinary" characters.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #47
Spiros Bousbouras wrote, On 12/05/08 22:50:
On 12 May, 21:24, Flash Gordon <s...@flash-gordon.me.ukwrote:
>Spiros Bousbouras wrote, On 12/05/08 20:45:
<snip>
>In any case, I would consider my comment valid whether the OP had
mentioned ANSI C, ISO C or just C.

I wasn't suggesting that your comment isn't valid
I was just curious which standard the OP is aiming
for.
OK, no problem.
--
Flash Gordon
Jun 27 '08 #48
On May 13, 1:24 am, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
Another problem: the program below reports

(test.c,10):error:struct or union member key doesn't exsist
(test.c,10):warning:conversion between pointer and integer without a cast

The error goes away if the "const" in the declaration of hp is
removed.

typedef struct hash_entry {
void *key;

} HashEntryStruct;

HashEntryStruct h;

int main(void)
{
const HashEntryStruct *hp = &h;
void *key = hp->key;

return 0;

}

-- Richard
--
:wq
Sorry this bug should be found before beta release. I wrote this
compiler at my spare time. Now I released its beta version
for more test. Now I received some feedbacks. If you will, hope that
you can send bug report to the address mentions at the document, or
you can submit it in sourceforge. I will try to set up the developer
community, update the release as soon as I can.
Jun 27 '08 #49
"no*************@gmail.com" wrote:
"noagbodjivic...@gmail.com" <noagbodjivic...@gmail.comwrote:
>dreamAnders <dream_and...@yahoo.com.cnwrote:
>>ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
.... snip ...
>>
Congratulations. I hope this project will evolve quickly.

Also, I don't really like the fact that one must have Ms Studio
to compile the compiler :) Can't you distribute binaries?
You mean it isn't even written in C? If so, that is the end of
that project.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fuzzyman | last post by:
What's the score on this (the ASPN python compiler) - is it a true compiler for python ? - what does it output - binary or C++ for .NET framework............ if the latter then it could be very...
14
by: Mark Dufour | last post by:
After nine months of hard work, I am proud to introduce my baby to the world: an experimental Python-to-C++ compiler. It can convert many Python programs into optimized C++ code, without any user...
43
by: Anitha | last post by:
Hi I observed something while coding the other day: if I declare a character array as char s, and try to use it as any other character array..it works perfectly fine most of the times. It...
3
by: babak | last post by:
Hi I am running a project in eVC 4.0 and I have been running into a bug that only appears in the release build of the project. I eventually found out that when I had the compiler option /Od set...
11
by: zeppe | last post by:
Hi all, I've a problem. The code that follows creates a warning in both gcc and visual c++. However, I think it's correct: basically, there is a function that return an object of a derived...
8
by: STG | last post by:
Greetings, My group has an SDK that was developed 5 years ago with VC++ 6. Over the last years, the requests for a VS.NET SDK has reached critical mass and I am now in the process of doing that....
15
by: linq936 | last post by:
Hi, I am reading book <<Expert C Programming>>, it has the following quiz, a //* //*/ b In C and C++ compiler what does the above code trun out? I think it is simple for C compiler, it is...
49
by: valentin tihomirov | last post by:
fDeleted = false; uint jobId; foreach (Struct struct in structures) { if (struct.type == JOB) { jobId = struct.id; if (struct.dataType == STATUS) fDeteted = (struct.data & STATUS_DELETED) !=...
3
by: gil | last post by:
Hi, I'm trying to find the best way to work with compiler warnings. I'd like to remove *all* warnings from the code, and playing around with the warning level, I've noticed that compiling with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.