Deutsch   English   Français   Italiano  
<87r0e8mx8s.fsf@tudado.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Johanne Fairchild <jfairchild@tudado.org>
Newsgroups: comp.lang.c
Subject: storage of string literals
Date: Sat, 11 May 2024 07:57:55 -0300
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <87r0e8mx8s.fsf@tudado.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sat, 11 May 2024 12:58:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cab564bdf742567f9f52b833b9d228ea";
	logging-data="2108537"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+xDoNmUKeEHYc8tuQ5bVJOw7xM8zU3x6w="
Cancel-Lock: sha1:4XxnzrrePnFbAlxnLiZv1V9UorQ=
	sha1:bojRmNP9SLLcGeBg9y6aFDVeYOw=
Bytes: 1877

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!