storage of string literals

Liste des GroupesRevenir à l c 
Sujet : storage of string literals
De : jfairchild (at) *nospam* tudado.org (Johanne Fairchild)
Groupes : comp.lang.c
Date : 11. May 2024, 12:57:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87r0e8mx8s.fsf@tudado.org>
I don't think the standard says anything about where a string literal
would be allocated.  Could a compiler allocate on the stack string
literals defined inside a procedure?  (Can I say that ``string
literals'' are /defined/ or should use a different word?)  So that, for
instance, when the procedure dealWord (below) returns, token->category
would point nowhere.

--8<-------------------------------------------------------->8---
typedef struct Token stoken;

struct Token {
  char *category;
};

void dealWord(stoken *token) {
  token->category = "cat1";
  [...]
}
--8<-------------------------------------------------------->8---

Section 6.2.4 of C99 has title ``storage durations of objects''.  Point
4 says

  --8<-------------------------------------------------------->8---
  An object whose identifier is declared with no linkage and without the
  storage-class specifier static has automatic storage duration.
  --8<-------------------------------------------------------->8---

Are string literals objects?  Thanks!

Date Sujet#  Auteur
11 May 24 * storage of string literals3Johanne Fairchild
11 May 24 +- Re: storage of string literals1Barry Schwarz
11 May 24 `- Re: storage of string literals1David Brown

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal