embedded questions!!!

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hello All,

Some questions were bugging me from quite some time. Any answers!
please share.

1.  GIven an .EXE is there a way to find how many global varibale it
uses?

2.  Given 2 Strings char *str1 = "JHONSON";
                            char *str2 = "O";

what is the fastest way to remove all occurences of letter O from str1.

3. Given 2 STACKS, how to implement a QUEUE?

4. what are MAK files? where are they used (Not quite C related but
just in case.)

5. what does .OBJ files contains?

6. how does DLL  link on runtime?

7. what is ELF format?

8. what is COFF format? what's it for?

9. why do we need so many file formats .HEX, S-REC to represent exe.

Best Regards,

#define


Re: embedded questions!!!
Quoted text here. Click to load it

I think your professor wants you to do
your own homework.


Re: embedded questions!!!
Hello All,

Some C questions were bugging me from quite some time. Any answers!
please share.

1.  GIven an .EXE is there a way to find how many global varibale it
uses?

2.  Given 2 Strings char *str1 = "JHONSON";
                            char *str2 = "O";

what is the fastest way to remove all occurences of letter O from str1.

3. Given 2 STACKS, how to implement a QUEUE?

4. what are MAK files? where are they used (Not quite C related but
just in case.)

5. what does .OBJ files contains?

6. how does DLL  link on runtime?

7. what is ELF format?

Best Regards,

#define


Re: embedded questions!!!
Quoted text here. Click to load it

Well, you've posted it twice, is your prof going to fail you twice?

It's the season of goodwill to all men - except people who are failing
100-level CS courses and trying to beg for answers on Usenet.  They
*deserve* to go to the wall.


pete
--
snipped-for-privacy@fenelon.com "there's no room for enigmas in built-up areas" - HMHB.

Re: embedded questions!!!

Quoted text here. Click to load it

str1[0] = '';

Rufus



Re: embedded questions!!!
Quoted text here. Click to load it

Bzzt - WRONG. str1 contains a pointer to a non-modifiable string
(which may well reside in ROM).  str1 itself contains no letter O.
  Thus the only way is:

   str1 = "JHNSN";

Things would be different if the original declaration was:

     char str1[] = "JHONSON";

which would have initialized a character array to a C string.

--
"If you want to post a followup via groups.google.com, don't use
  the broken "Reply" link at the bottom of the article.  Click on
We've slightly trimmed the long signature. Click to see the full one.
Re: embedded questions!!!
Quoted text here. Click to load it
Or Not... this type of thing can be very compiler dependent!


Paul


Re: embedded questions!!!
Quoted text here. Click to load it

No.  The behaviour is spelled out in the C standard.

--
"If you want to post a followup via groups.google.com, don't use
  the broken "Reply" link at the bottom of the article.  Click on
We've slightly trimmed the long signature. Click to see the full one.
Re: embedded questions!!!
Quoted text here. Click to load it

 From My K&R (closest thing I have handy to the actual standard
it says:

"A Character array whose members are initialised with a string,
its size includes the null terminating character".

On a host system with a modern compiler you are 100% correct.

On an 8-bit embedded systems... I have seen compilers
that will store the string in ROM. All the while
claiming to be ANSI Compliant!

The problem is to do this properly on an embedded
system the compiler has to actually copy the
data from ROM to the string.


Regards


Paul

Re: embedded questions!!!
Quoted text here. Click to load it

I would say those compilers are just broken.

Quoted text here. Click to load it

And that is *exactly* what it should do, but why is that a problem ?
It is not any different then declaring and initializing an int, for
example :

    int a = 5;
    int b[] = { 1, 2, 3 };
    char msg[] = "Hello";


--
:wq
^X^Cy^K^X^C^C^C^C

Re: embedded questions!!!

Quoted text here. Click to load it

A yeah, very helpful - tail wagging the dog methinks.

Quoted text here. Click to load it

You really don't have a clue about managing scarce resources do you?

Ian

Re: embedded questions!!!
Quoted text here. Click to load it

I don't see how I could be helpful at all in this case. I believe that
having a compiler that by default stores

    char msg[] = "Hello";

into read only memory really *is* broken, and there is nothing I can do
about that by writing in a newsgroup, is there ?

Quoted text here. Click to load it

I forgot to mention that this is not a job for the compiler, but for the
C startup code, ofcourse.

Quoted text here. Click to load it

I may not know all about it, but while spending my last few years coding
C and assembly on tiny embedded platforms, I might have learned
*something* about scarse resources, I hope. Apart from that, I do not
understand what broken compilers and not having a clue about scarce
resources have to do with each other ?

Since I am not a C expert by any means, I would like to invite you to
continue this discussion on comp.lang.c; I assume there are people there
who can shed some light on this issue.

Ico

--
:wq
^X^Cy^K^X^C^C^C^C

Re: embedded questions!!!
Quoted text here. Click to load it

I think you have missed the entire point.  Something declared as:

     char *s = "string";

declares a non-writeable "string" which may be in rom.  However

     char s[] = "string";

declares a 7 byte char array, which must be writable, and is
initialized to contain "string".  Here, in most cases, the value
of s is passed as a pointer to the first char of "string".

As a result, a function

    T foo(char *stg)

called by

    foo(s);

will receive the same _value_ in the parameter stg for either
original declaration.  However in one case *stg is writable, in the
other it is not.

gcc allows the 'char *s = "string"' to imply const char.  This is
helpful in tracking down bugs if you use const correctly elsewhere.

--
"If you want to post a followup via groups.google.com, don't use
  the broken "Reply" link at the bottom of the article.  Click on
We've slightly trimmed the long signature. Click to see the full one.
Re: embedded questions!!!
On 12/01/2006 the venerable Chuck F.  etched in runes:

Quoted text here. Click to load it
well reside in ROM).
Quoted text here. Click to load it

Bzzzzt - WRONG.

A pointer to non-modifiable string would be declared as

    const char *str1 = "JHONSON";


The two declarations:

    char str1* = "JHONSON";

and

    char str2[] = "JHONSON";

both allocate space for a modifiable string. The difference being that the first
one also creates a
pointer to that string.


--
John B

Re: embedded questions!!!

Quoted text here. Click to load it
may well reside in ROM).
Quoted text here. Click to load it
first one also creates a
Quoted text here. Click to load it

Isn't str2 also a pointer?

BTW, I will admit a recurring problem with understanding the nuances of C
pointers.



Re: embedded questions!!!
On Fri, 13 Jan 2006 07:16:56 -0800 in comp.arch.embedded, "Richard

Quoted text here. Click to load it
[...]
Quoted text here. Click to load it

No.

Repeat after me: "Arrays are not pointers.  Pointers are not arrays."
Despite what you may have been told.

A pointer is an object that references some other object.

An array is a group of contiguously allocated objects of the same
type.  

(This is the important bit)  The unadorned name of an array devolves
into a pointer to the first element of that array.  Sort of like a
compile-time constant.

One point of confusion is the mechanism of array indexing.  The syntax
"a[i]" has *exactly* the same meaning as "(*a + i)" whether a is a
pointer or array.  So given the declarations above, str1[0] == 'J' ==
str2[0].  

Another is the syntax for passing an array as a parameter to a
function.  Thus "Fn(str1);" looks to be much the same as "Fn(str2);"
but the actual semantics are a bit different.  Inside the function
itself, of course, the parameter is the same in either case.

Quoted text here. Click to load it

Peter van der Linden's "Expert C Programming: Deep C Secrets" has one
or two excellent chapters on the differences between arrays and
pointers (as well as sections on understanding and contruction C
declarations, and other topics introductory books are to timid to
tackle).  Somewhat dated (it was written about a dozen years ago), but
very readable and recommended.  You don't read it because you're an
expert already, you read it to become expert...

Regards,
                                        -=Dave

--
Change is inevitable, progress is not.

Re: embedded questions!!!

Quoted text here. Click to load it
the

I will defer to you knowledge of C pointers.

However, my confusion about them has only increased.



Re: embedded questions!!!

Quoted text here. Click to load it

AHA! Breakthrough! Now you're getting it.

;)


Bob


Re: embedded questions!!!

Quoted text here. Click to load it

You mean *((a)+(i)).  Or perhaps more precisely, to capture usual
unary conversion rules, *((&a[0])+(i)).

Jon

Re: embedded questions!!!
On Fri, 13 Jan 2006 19:18:53 GMT in comp.arch.embedded, Jonathan

Quoted text here. Click to load it

Actually, I meant "*(a + i)".  Apologies for fat-fingering that.  I
think, however, the additional parentheses in *((a)+(i)) are
redundant, at least if a[i] is a well-formed expression.

Quoted text here. Click to load it

Well, no, actually, that's not necessary, and arguably wrong. Consider
i[a], which should be equivalent to a[i].

Regards,
                                        -=Dave

--
Change is inevitable, progress is not.

Site Timeline