Question C code compilation

Question C code compilation

Post by kishu » Tue, 29 Jul 2003 09:30:04



Hi All,

I wrote simple program to print "Hi how are you" 100,000 times and
compiled on Redhat Linux.

test.c

  main()
    {
       printf("Hi How are you");
         .
         .
         .
       /*Repeated printf for more one hundread thousand times */
    }

then

did #make test
  cc test.c -o test

this command did NOT exit for more than half hour, later I did
control-c to exit.

Please tell me why I can't compile this long code?, what would be the
best approach other than splitting the code.

thanks
kishuri

 
 
 

Question C code compilation

Post by Steve Wa » Tue, 29 Jul 2003 09:59:34




>Hi All,

>I wrote simple program to print "Hi how are you" 100,000 times and
>compiled on Redhat Linux.

>test.c

>  main()
>    {
>       printf("Hi How are you");
>         .
>         .
>         .
>       /*Repeated printf for more one hundread thousand times */
>    }

>then

>did #make test
>  cc test.c -o test

>this command did NOT exit for more than half hour, later I did
>control-c to exit.

>Please tell me why I can't compile this long code? [ ... ]

Because you didn't wait long enough.

Quote:>                                                    what would be the
>best approach other than splitting the code.

A for loop?

What's the real problem you're trying to solve?  Are you trying to
figure out what the largest program you can compile is?

For that matter, what does this have to do with embedded systems?
--
Steve Watt KD6GGD  PP-ASEL-IA          ICBM: 121W 56' 57.8" / 37N 20' 14.9"

   Free time?  There's no such thing.  It just comes in varying prices...

 
 
 

Question C code compilation

Post by kishu » Tue, 05 Aug 2003 15:05:38





> >Hi All,

> >I wrote simple program to print "Hi how are you" 100,000 times and
> >compiled on Redhat Linux.

> >test.c

> >  main()
> >    {
> >       printf("Hi How are you");
> >         .
> >         .
> >         .
> >       /*Repeated printf for more one hundread thousand times */
> >    }

> >then

> >did #make test
> >  cc test.c -o test

> >this command did NOT exit for more than half hour, later I did
> >control-c to exit.

> >Please tell me why I can't compile this long code? [ ... ]

> Because you didn't wait long enough.

> >                                                    what would be the
> >best approach other than splitting the code.

> A for loop?

> What's the real problem you're trying to solve?  Are you trying to
> figure out what the largest program you can compile is?

> For that matter, what does this have to do with embedded systems?

I know your embedded world is different. However, every embedded
systems do need a compiler and an operating system. This Question
falls under these two sections of embedded systems. Are not there any
better way to generate code, why does it fail or take longer when
compiling huge function like here main()? How long your embedded OS
take to compile this. If fails, how can you fix it? Think over it
before questioning others.
thanks,
kishuri
 
 
 

Question C code compilation

Post by Steve Wa » Tue, 05 Aug 2003 16:19:57







>> >  main()
>> >    {
>> >       printf("Hi How are you");
>> >       /*Repeated printf for more one hundread thousand times */
>> >    }

>> >then

>> >did #make test
>> >  cc test.c -o test

>> >this command did NOT exit for more than half hour, later I did
>> >control-c to exit.

[ ... ]
>> A for loop?

>> What's the real problem you're trying to solve?  Are you trying to
>> figure out what the largest program you can compile is?

>> For that matter, what does this have to do with embedded systems?

>I know your embedded world is different. However, every embedded
>systems do need a compiler and an operating system. This Question

Absolutely embedded systems need compilers.  Embedded systems do not, as
a class, require operating systems, and percentage-wise, more embedded
systems don't have a recognizable OS than do.  However, since you're in
the embedded Linux newsgroup (comp.os.linux.embedded), I was expecting
your question to somehow be relevant to embedded systems.

Quote:>falls under these two sections of embedded systems. Are not there any

If you're not going to tell me what the problem you're really trying
to solve is, I can't help any more.  To solve the problem of executing
printf() 100k times, use a for loop.  It'll compile much more quickly,
and use less code space.  And with cache effects of huge programs, I'll
bet it even runs slightly faster.

Using Linux in an embedded environment is not magic, and there really
isn't any such thing as "embedded Linux" -- the kernel being used in an
embedded way is not fundamentally different than any other particular
Linux kernel.  Yes, there are different ways to deploy it, and different
challenges dealing with embedded targets, which is why this group
exists.

Quote:>better way to generate code, why does it fail or take longer when
>compiling huge function like here main()?  [ ... ]

The compiler most people use for embedding Linux is GCC.  It's certainly
the one I use.    It takes longer because there's more work to do, and
quite honestly, no sensible person has 100,000 lines of source in a
single function in a single file.  On a modern box, 100k lines of code
broken into sensible modules should take about an hour to compile.

Quote:>                                          How long your embedded OS
>take to compile this. If fails, how can you fix it? Think over it
>before questioning others.

My OS (Linux, at the moment) doesn't compile anything.  I don't run
the compiler on my embedded target, either, as it doesn't have enough
resources.

If an engineer who is reporting to me were to approach me and say the
compiler needed fixing because it failed to work within half an hour
on a rediculously sized source file, I would take a look at what was
really trying to be accomplished and suggest breaking the file
(both the function and the file, really) into multiple, smaller
modules.  And if the engineer persisted, even for a moment, at insisting
s/he needed a single file of that size without a good, compelling
argument why, I would probably inform management that a reassignment
might be in order.

I am sorry if you interpret my question as some kind of attack.  I
want to understand what you're really trying to do so I can suggest
better ways of approaching it.
--
Steve Watt KD6GGD  PP-ASEL-IA          ICBM: 121W 56' 57.8" / 37N 20' 14.9"

   Free time?  There's no such thing.  It just comes in varying prices...

 
 
 

Question C code compilation

Post by Wolfgang Den » Tue, 05 Aug 2003 18:28:22




>>> >  main()
>>> >    {
>>> >       printf("Hi How are you");
>>> >       /*Repeated printf for more one hundread thousand times */
>>> >    }

>>> >then

>>> >did #make test
>>> >  cc test.c -o test

>>> >this command did NOT exit for more than half hour, later I did
>>> >control-c to exit.

Actually this is an  indication  of  extreme  low  resources  on  the
development host. I just tested this on a standard PC running Linux:

        bash$ time gcc -o foo foo.c

        real    0m13.948s
        user    0m12.880s
        sys     0m0.230s

As you can see, it took just 14 seconds to compile your program.

And this is no high-end machine  at  all.  It's  a  standard  AMD  XP
processor at 2083 MHz with 512 MB RAM.

Quote:>single function in a single file.  On a modern box, 100k lines of code
>broken into sensible modules should take about an hour to compile.

I have not the slightest idea where you get such a  number  from.  To
build a medium-sized project (U-Boot) with some 350k+ lines of C code
(_not_  counting  the  header and assembler files) takes less than 20
seconds on an even slower machine (AMD Athlon at 1400 Mhz).

Your number is approx. 600 times too big!

Wolfgang Denk

--
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88   Web: www.denx.de
"The pathology is to want control, not that you ever get it,  because
of course you never do."                            - Gregory Bateson

 
 
 

1. Question on coding style in networking code

Hello All,
        First off, this is probably a straight C question, but here goes...

        I was looking at the kernel code, and in protocol.c the protocol structures are
instansiated and filled.  Now, I have seen/used the following syntax:
        struct x y = { x, y, z };

I have not seen the following:
        struct x y = {
                member1: x,
                member2: y,
                member3: z
        };

What is the deal with this?  Does the second way have any advantage over the previous?

Thanks in advance,
Chuck

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. eject -t on Linux. How about eject -t on Solaris???

3. code errors in php compilation

4. Solaris 2.5 & Solaris 2.5.1

5. RTFM (where)? in kernel/modulad code compilation

6. Oracle WebServer for Linux

7. Compilation problem with C++ code !!!

8. Cleaning pipe buffer

9. Coding for cross compilation

10. GNU OBJECTIVE C and NeXt source code .m file compilation

11. Cross compilation compilation problems

12. Compilation Questions !

13. Kernel compilation question.