LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-27-2007, 09:18 AM   #16
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45

> FYI "unspecified" is a code word for "It may or may not work

99% of the time, attempting to modify a literal will result in a segfault, you should declare literal declarations as const to help prevent modifying them.

Quote:
char * should point at some previously allocated data.
char [] will have space allocated in your heap or stack space.
i would word it, char[] cannot be null and char* could or just as well could not point to previously allocated data (as a * is null just as often as it is not)
 
Old 04-03-2007, 10:28 AM   #17
kourama
LQ Newbie
 
Registered: Sep 2006
Distribution: Mint64 w/KDE
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jim mcnamara
This is not good. Nobody mentioned the C99 standard and what it says:

1. char var[]="abc";
This creates an array of char which is modifable
2. char *var="abc";
This creates an array of char, the results of modifying it are unspecified.

FYI "unspecified" is a code word for "It may or may not work. But don't expect to be able to port the code just because some compiler writer was nice enough to make it work for your platform."
In short "don't modify it"

3. char *var=NULL; [ or char *var; ] is a pointer to char and is modifable.
Although somewhat tangent, that's an excellent point. I have a copy of a recent C standards document somewhere. I oughta look at it every now and then!

Apologies for post<quote etiquette violation.
 
  


Reply

Tags
array, pointers, reference



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie question: whats the difference between "su root", "su" and "su -&quo mojarron Slackware 9 12-07-2009 04:08 PM
Renamed bogus "/var/mail/macleanl" into "/var/mail/BOGUS.macleanl.xPVB" paul_mat Linux - Networking 1 07-04-2006 12:50 PM
using symlinks for /home/"username" and /var/www/html hamza11050 Linux - Networking 10 08-05-2005 10:36 PM
Boot messages not the same as "dmesg" or "/var/log/messages"? massai Linux - General 5 03-10-2004 12:18 AM
sshd error " bad owner or mode for /var/empty" piraxter Slackware 1 09-09-2003 11:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration