Sida 4 av 8
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 2 oktober 2019, 20:52:55
av snigelen
TomasL skrev:Det är fel, C89/C90 finns inte längre, de är tillbakadragna av ISO/ANSI-
ANSI C refererar alltid till den senaste standarden vilket i dag är C18, dvs C11 med alla tillägg och ändringar.
Du har lite (mycket) redigeringsjobb att göra på wikipedia. T.ex.
Compilers supporting ANSI C
Amsterdam Compiler Kit (C K&R and C89/90)
ARM RealView
Clang, using LLVM backend
GCC (full C89/90, C99 and C11)
HP C/ANSI C compiler (C89 and C99)[29]
IBM XL C/C++ (C11, starting with version 12.1)[30]
Intel's ICC
LabWindows/CVI
LCC
OpenWatcom (C89/90 and some C99)
Microsoft Visual C++ (C89/90 and some C99)
Pelles C (C99 and C11. Windows only.)[31]
vbcc (C89/90 and C99)
Tiny C Compiler (C89/90 and some C99)
Oracle Developer Studio
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 2 oktober 2019, 21:15:42
av DanielM
Finns dock inget annat man kan använda som är rekrusivt. Visst finns N4SID, men det har sina nackdelar att man använder SVD och QR faktorisering. Väldigt tunga verktyg.
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 2 oktober 2019, 23:05:05
av Mr Andersson
Säger man ANSI C kommer nog nästan alla förutsätta att man menar C89 eftersom det är den enda standarden som är skapad av ANSI.
Efter det tog ISO över ansvaret för språkstandarden.
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 2 oktober 2019, 23:25:30
av TomasL
Och, ANSI drog tillbaka standarderna, vilket i praktiken innebär att det inte finns några ANSI-C kvar, utan det ISO C11-C18 som gäller.
per definition är ANSI-C C11/18
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 2 oktober 2019, 23:31:17
av sodjan
Bara för att ANSI inte längre aktivt jobbar med det betyder ju inte
att kompilatorer som följde en viss ANSI-C standard slutar fungera.
Så snacket om att "dra tillbaka" en standard är ganska ointressant.
Och även om det är ANSI eller ISO som sköter om det praktiska...
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 2 oktober 2019, 23:39:46
av TomasL
Jovisst, men om man säger att man genererar kod per ANSI-C, eller att en kompilator är ANSI-C Så är det per definition C18 som gäller.
En kompilator eller verktyg som genererar kod enligt C89/90 är inte ANSI-Kompatibel, punkt.
Sedan får alla andra tycka vad de vill.
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 2 oktober 2019, 23:56:22
av Mr Andersson
sodjan skrev:Bara för att ANSI inte längre aktivt jobbar med det betyder ju inte
att kompilatorer som följde en viss ANSI-C standard slutar fungera.
Så snacket om att "dra tillbaka" en standard är ganska ointressant.
Och även om det är ANSI eller ISO som sköter om det praktiska...
Absolut, rent praktiskt är det helt ointressant vem som sätter sitt namn på standarden.
Jag syftade bara på terminologin som används inom programmeringsindustrin*.
Säger man ansi c menar man gammal c-kod. Använder man nyare standarder säger man explicit vilken version det är.
*) Kanske mest i USA? Jag har inte arbetat som C-programmerare i sverige.
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 3 oktober 2019, 00:30:27
av sodjan
Ja, så är det ju, man använder uttrycket "ANSI-C" för att skilja något från
nyare standards. Här är ett exempel från en C kompilator. Stöder i och för
sig inte C11/C18, men gör ändå skillnad på ANSI-C och de senare C88 och
C99, C94 namns också plus lite annat...:
Kod: Markera allt
$ help cc /standard
CC
/STANDARD
/STANDARD=(option)
/STANDARD=RELAXED (equivalent to /NOSTANDARD) (D)
/NOSTANDARD (D)
Defines the compilation mode. You can select the following
options:
ANSI89 Places the compiler in strict ANSI C Standard 89
(C89) mode. This mode compiles the C language as
defined by the American National Standard for C,
along with any extensions not prohibited by that
standard.
C99 On OpenVMS Alpha and I64 systems, places the
compiler in strict ISO/IEC C Standard 99 (C99)
mode. This mode accepts just the C99 language
without extensions, and diagnoses violations of
the C99 standard. /STANDARD=C99 defines the
__STDC_VERSION__ macro to the C99-specified value
of 199901L, because C99 is a superset of
Amendment 1 to the C89 standard, and the default
mode of RELAXED is a superset of C99.
On OpenVMS VAX systems, produces a warning and
places the compiler in /STANDARD=RELAXED ANSI89
mode.
LATEST On OpenVMS Alpha and I64 systems, places the
compiler in the latest ISO C standard dialect.
/STANDARD=LATEST is currently equivalent to
/STANDARD=C99, but is subject to change when
newer versions of the ISO C standard are
released.
RELAXED Places the compiler in relaxed ANSI C Standard
mode. The compiler accepts ANSI/ISO C Standard
C89 and C99 features, as well as nearly all
language extensions (such as additional VSI C
keywords and predefined macros that do not begin
with an underscore). It excludes only K&R
(COMMON mode), VAX C, and Microsoft features that
conflict with standard C.
This is the default mode of the compiler, and is
equivalent to /NOSTANDARD.
MS Places the compiler in Microsoft compatibility
mode, which interprets source programs according
to certain language rules followed by the C
compiler provided with the Microsoft Visual C++
compiler product.
ISOC94 Places the compiler in ISO C 94 mode, which
enables digraph processing. It also defines the
predefined macro __STDC_VERSION__=199409 when
specified alone or in combination with the
ANSI89, MIA, RELAXED, MS, COMMON, or PORTABLE
keywords.
This option can be specified alone or with any
other /STANDARD option except VAXC. If it is
specified alone, the default major mode is
RELAXED.
COMMON Places the compiler in K & R language mode; that
is, compatibility with older UNIX compilers such
as pcc and gcc. This mode is close to a subset
of /STANDARD=VAXC mode.
VAXC Places the compiler in VAX C mode. There are
differences in the C language as implemented in
previous versions of VAX C and the C language as
defined by ANSI (the differences are primarily
concerned with how the preprocessor works). This
mode provides compatibility for programs that
depend on old VAX C behavior.
PORTABLE Places the compiler in RELAXED mode, and enables
the issuance of diagnostics that warn of any
nonportable usages encountered.
Note that /STANDARD=PORTABLE is supported for
VAX C compatibility only. It is equivalent to
the recommended combination of qualifiers
/STANDARD=RELAXED /WARNINGS=ENABLE=PORTABLE.
MIA Places the compiler in strict ANSI C mode with
the following behavior differences to conform to
the Multivendor Integration Architecture (MIA)
standard:
o On OpenVMS VAX systems, G_FLOAT becomes the
default floating-point format for double
variables. (On OpenVMS Alpha systems, G_FLOAT
is already the default.)
o In structures, zero-length bit fields cause
the next bit field to start on an integer
boundary, rather than on a character boundary.
If the /STANDARD qualifier is not specified, the default is
/NOSTANDARD, which is equivalent to /STANDARD=RELAXED.
If you specify the /STANDARD qualifier, you must supply an option.
With one exception, the /STANDARD qualifier options are mutually
exclusive. Do not combine them. The exception is that you can
specify /STANDARD=ISOC94 with any other option except VAXC.
VSI C modules compiled in different modes can be linked and
executed together.
Topic?
$
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 4 oktober 2019, 21:26:52
av DanielM
Vill tacka alla för att ha deltagit i denna diskussion. Vi kan sammanfatta att vi har kommit fram till:
- Malloc, free och calloc är totalt förbjudet att använda under körning. Undantag finns vid initialisering utav minne. Men undvik helst.
- Anropa samma funktion rekrusivt t.ex. att man är "innuti funktionen" och man anropar den igen, är totalt förbjudet.
- Använd inte int, utan uint8_t, unit16_t, uint32_t för att vara nogrannare på minnet
- ANSI C är inte C89. Utan det är senaste C standarden. Senaste idag är C18. Dock liten skillnad jämfört mot C89 om man ska jämföra C++ 98 med C++ 20 då C ändrar sig sällan.
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 4 oktober 2019, 21:54:32
av TomasL
Då är den STORA frågan, har du förstått varför.
Har du läst MISRA och förstått den?
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 4 oktober 2019, 22:07:30
av DanielM
Tyvärr så har jag inte förstått MIRSA C och därför vände jag mig till er för att veta praktiskt hur det är. Standarder, kurser och teori kan skilja väldigt mycket hur man gör i verkligheten.
Det jag har förstått är att statiskt minne är positivt och dynamiskt minne är negativt.
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 4 oktober 2019, 22:18:38
av Icecap
Läs DanielM's inlägg då, det är mycket av vad som är viktigt.
MISRA C är regler man använder för att det ska skita sig minst möjligt. C som verktyg är mycket starkt - man kan skjuta ett enormt hål i egen fot med det! Men följer man MISRA C är risken mindre och planerar man sitt jobb minskar den ytterligare.
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 4 oktober 2019, 23:34:15
av DanielM
Jo. Det går att beskriva MIRSA C med egna unika känslor, men en praktisk lista är vad många här skulle lättare kunna ta del utav.
Jag vet att C är ett kraftfullt verktyg, men det finns bättre vektyg om vi tittar på vad språket kan och inte kan.
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 5 oktober 2019, 00:06:55
av hummel
MISRA C är i princip en lista med 127 punkter på det du ska tänka på eller undvika.
Re: Allokering utav minne - Acceptabelt inom inbyggda syste
Postat: 5 oktober 2019, 00:22:23
av DanielM
Hittar inte denna lista någonstans. Finns säkert in MIRSA C's standard, men att sammanfatta denna har jag ej tid med.