public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Help wanted
@ 2003-03-17 16:44 Jane Liang
  2003-03-17 16:53 ` Ben Davis
  0 siblings, 1 reply; 6+ messages in thread
From: Jane Liang @ 2003-03-17 16:44 UTC (permalink / raw)
  To: 'GCC-help'


[-- Attachment #1.1: Type: text/plain, Size: 677 bytes --]

Hi, all:

I have a simple program(see below), it ran without any problem in sun (with
sun's compiler). However, when I compiled it in gcc on PC, it crashed at
line 13.  I tried to use strtok and some other string functions but none of
them seems works fine.  Does anyone know why?

Thanks!

Jane


Line 1    #include <stdlib.h>
Line 2    #include <stdio.h>
Line 3    #include <string.h>
Line 4
Line 5    int main()
Line 6    {
Line 7
Line 8      char *str = "0.12000, 0.0, 0.0";
Line 9      char *ptr;
Line 10     float  num;
Line 11
Line 12     ptr = strchr(str, ',');
Line 13     *ptr = '\0';
Line 14 
Line 15     num = atof(str);
Line 16
Line 17     return 0;
Line 18   }



[-- Attachment #1.2: Type: text/html, Size: 2213 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help wanted
  2003-03-17 16:44 Help wanted Jane Liang
@ 2003-03-17 16:53 ` Ben Davis
  0 siblings, 0 replies; 6+ messages in thread
From: Ben Davis @ 2003-03-17 16:53 UTC (permalink / raw)
  To: Jane Liang, 'GCC-help'

On Monday 17 March 2003 4:26 pm, Jane Liang wrote:
> Line 8      char *str = "0.12000, 0.0, 0.0";

This is a constant string, so it is stored in read-only memory.

> Line 13     *ptr = '\0';

You are now writing to read-only memory. Hence the crash.

You can fix your code by making 'str' an array instead:

   char str[] = "0.12000, 0.0, 0.0";

Then the string will be stored temporarily on the stack, which is writable. 
The array will be just the right size to accommodate the string.

When using GCC, I recommend you compile with -Wwrite-strings. String constants 
will then be given the 'const' qualifier, and you will get a warning if you 
don't use 'const' yourself where necessary:

   const char *str = "0.12000, 0.0, 0.0";

Ben

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Help wanted
@ 2003-03-17 19:16 Jane Liang
  0 siblings, 0 replies; 6+ messages in thread
From: Jane Liang @ 2003-03-17 19:16 UTC (permalink / raw)
  To: 'Ben Davis', Jane Liang, 'GCC-help'

Hi, Ben:

It works!

Thanks!
 
Jane


-----Original Message-----
From: Ben Davis [mailto:bnd25@cam.ac.uk] 
Sent: Monday, March 17, 2003 10:54 AM
To: Jane Liang; 'GCC-help'
Subject: Re: Help wanted


On Monday 17 March 2003 4:26 pm, Jane Liang wrote:
> Line 8      char *str = "0.12000, 0.0, 0.0";

This is a constant string, so it is stored in read-only memory.

> Line 13     *ptr = '\0';

You are now writing to read-only memory. Hence the crash.

You can fix your code by making 'str' an array instead:

   char str[] = "0.12000, 0.0, 0.0";

Then the string will be stored temporarily on the stack, which is writable. 
The array will be just the right size to accommodate the string.

When using GCC, I recommend you compile with -Wwrite-strings. String
constants 
will then be given the 'const' qualifier, and you will get a warning if you 
don't use 'const' yourself where necessary:

   const char *str = "0.12000, 0.0, 0.0";

Ben

^ permalink raw reply	[flat|nested] 6+ messages in thread

* help wanted
@ 2002-08-12  8:22 rojesh  p
  0 siblings, 0 replies; 6+ messages in thread
From: rojesh  p @ 2002-08-12  8:22 UTC (permalink / raw)
  To: gcc-help

     The 8051 does not seem to have a GCC back end. we are trying 
to develop a backend one. where can we get the details about the 
rtl syntax(other than porting and using gcc). please help us.

__________________________________________________________
Give your Company an email address like
ravi @ ravi-exports.com.  Sign up for Rediffmail Pro today!
Know more. http://www.rediffmailpro.com/signup/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: help wanted
  2001-10-10 22:06 Danish Samad
@ 2001-10-10 23:44 ` Rupert Wood
  0 siblings, 0 replies; 6+ messages in thread
From: Rupert Wood @ 2001-10-10 23:44 UTC (permalink / raw)
  To: 'Danish Samad'; +Cc: gcc-help

Danish Samad wrote:

> The GCC project I have downloaded is huge containing a lot of other
> compilers, assemblers etc. Can you please guide me where to find the
> gcc c compilers front end with documentation.

There's plenty of it, yes, but if you're going to attempt some heavy
backend wizardry then you will have to get your head around most of it
sooner or later.

Unless you have a merged gcc-binutils tree (not likely if you downloaded
it yourself) then you don't actually have any assemblers bundled.
Instead, you have

   /                 Top level makefiles for cygnus toolchain
   /gcc              C front end and generic backend
   /gcc/config       CPU/OS specific instruction sets and ABIs
   /gcc/cp           C++ front end
   /gcc/objc         Objective-C front end
   /gcc/f            Fortran front end
   /gcc/java         Java front end
   /gcc/po           Internationalization 'pot' translation files
   /gcc/intl         Internationalization library
   /gcc/fixinc       Fixes for non-standards-conformant system headers
   /gcc/doc          Documentation
   /gcc/ginclude     GCC build includes
   /gcc/testsuite    GCC regression testsuite

etc. plus a number of runtime libraries and helper libraries (libiberty)
at the top level.

i.e. you'll find the C-front end and the generic backend in the gcc
directory, plus you'll need one of the machine description files (.md)
plus a number of headers and source files in the config tree to tell the
generic backend how to generate processor specific code.

All documentation is build with GCC into at least .info format. It is
also available online at http://gcc.gnu.org/onlinedocs/

Good luck!

Rup.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* help wanted
@ 2001-10-10 22:06 Danish Samad
  2001-10-10 23:44 ` Rupert Wood
  0 siblings, 1 reply; 6+ messages in thread
From: Danish Samad @ 2001-10-10 22:06 UTC (permalink / raw)
  To: gcc-help

hello

I have been assigned the task to design and develop an
optimizing C compiler which generates instructions
capable of executing in parallel. For this purpose we
have decided to use gcc c compiler front end and
design our own backend. The GCC project I have
downloaded is huge containing a lot of other
compilers, assemblers etc. Can you please guide me
where to find the gcc c compilers front end with
documentation. Please reply as soon as possible

thanks,
danish 

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-03-17 16:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-17 16:44 Help wanted Jane Liang
2003-03-17 16:53 ` Ben Davis
  -- strict thread matches above, loose matches on Subject: below --
2003-03-17 19:16 Jane Liang
2002-08-12  8:22 help wanted rojesh  p
2001-10-10 22:06 Danish Samad
2001-10-10 23:44 ` Rupert Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).